Home › Forums › Front-end Issues › Get Post/Pages based on ACF checkbox › Reply To: Get Post/Pages based on ACF checkbox
Hi @astrixoblix
You will need to populate the meta_query args based on the checkbox value you have. Something like this should work:
<?php
$checkbox_field = get_field( 'checkbox_field', $post->ID );
$args = array(
'post_type' => 'page',
'post__not_in' => array( $post->ID ),
'posts_per_page' => $related_no,
'meta_query' => array(
'relation' => 'OR',
)
);
if( $checkbox_field )
{
foreach( $checkbox_field as $v )
{
$args['meta_query'][] = array(
'key' => 'checkbox_field',
'value' => '"' . $v . '"',
'compare' => 'LIKE'
);
}
}
// test args
echo '<pre>';
print_r($args);
echo '</pre>';
die;
?>
Hope that helps.
Thanks
E
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.