Home › Forums › General Issues › Why isn't Meta query working with ACF? › Reply To: Why isn't Meta query working with ACF?
I’m using a POST OBJECT acf field called “special_id” for a custom post type called ‘pencils’. If I remove the meta query from the args, I get the list of all Pencil posts it can find (drafts, specifically). When I add this meta_query, I get nothing back. Even though there are many draft posts with special_id “470”. I can use get_field(“special_id”, $pencil_type_id); and get the number 470 back.
But why can’t I query for those with this (or any) matching id? Do I have a typo or something?
$args = array(
‘post_type’ => ‘pencils’,
‘post_status’ => array(‘draft’),
‘numberposts’ => -1,
‘meta_query’ => array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘special_id’,
‘value’ => 470,
‘compare’ => ‘=’,
),
array(
‘key’ => ‘special_id’,
‘value’ => array(470),
‘compare’ => ‘=’,
),
),
);
$posts = get_posts($args);`
get_post_meta( $some_pencil_id ) returns successfully:
meta: Array
(
...
[special_id] => Array
(
[0] => 470
)
...
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.