Home › Forums › ACF PRO › Check posts for Custom Field › Reply To: Check posts for Custom Field
Hi
Sorry; that’s not the bit i’m stuck on.
It’s the actual meta_query loop that doesn’t appear to be working. I’m just wondering if my ‘value’ & ‘compare’ values are correct?
/*
* Query posts for a true/false value.
* This method uses the meta_query param to match the string “1” to the database value “1|0”
*/
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'field_name',
'value' => '1',
'compare' => '=='
)
)
));
if( $posts )
{
foreach( $posts as $post )
{
setup_postdata( $post );
// ...
}
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
}
What should my value and compare values be?
Thanks
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.