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!
📣 “ACF Chat Fridays”
— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.