Skip to content

Instantly share code, notes, and snippets.

@qwersk
Created June 28, 2017 07:18
Show Gist options
  • Save qwersk/038c755bdf0efdbc72c924a43d9ebb0d to your computer and use it in GitHub Desktop.
Save qwersk/038c755bdf0efdbc72c924a43d9ebb0d to your computer and use it in GitHub Desktop.
QUERY BY ACF FIELD #WORDPRESS
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'document_%", "meta_key LIKE 'document_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array(
'numberposts' => -1,
'post_type' => 'course',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'document_%_type',
'value' => $document,
'compare' => 'IN'
),
array(
'key' => 'form_of_edu',
'value' => $form_of_edu,
'compare' => 'IN'
),
array(
'key' => 'type',
'value' => $type,
'compare' => 'IN'
)
)
);
$query = new WP_Query( $args );
$arr = $query->posts;
print_r($arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment