Home › Forums › General Issues › check box query › Reply To: check box query
Hi @saberap
I’m afraid I don’t understand your goal. Could you please let me know the result you want?
Also, it seems there are some syntax errors in your code. First, you forgot to add the PHP closing and opening tag before and after the div element. Second, kindly avoid using $posts
variable as it’s sometimes used by WordPress. Third, you need to loop through the returned posts list to show the checkbox value for each post. And lastly, you need to pass the post ID because the code is executed outside of The Loop.
So, it should be like this:
<?php
// use another variable than "$posts"
$the_posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'facilities', // name of custom field
'value' => '"red"', // matches exactly "red"
'compare' => 'LIKE'
)
)
));
// don't forget the PHP closing tag
?>
<div class="facilities">
<?php
// and also the PHP opening tag
if( $the_posts ) {
// loop through the posts
for( $the_posts as $the_post ){
// show the value
the_field('facilities', $the_post->ID );
}
}
?>
</div>
I hope this makes sense 🙂
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.