Home › Forums › Front-end Issues › Get Post/Pages based on ACF checkbox › Reply To: Get Post/Pages based on ACF checkbox
Hi @elliot
Yes. i’m getting the values of current post’s checkbox via get_field, and i’m trying to find any pages which have any of current checkbox values.
as i said, i’m trying to create something like ‘related post’ but via ACF checkbox.
i’m not sure how i should dynamically generate the meta_query args array.
i tried this code:
$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',
array(
'key' => 'checkbox_field',
'value' => $checkbox_field ,
'compare' => 'IN'
)
)
);
didn’t worked.
removing ‘relation’ => ‘AND’, adding meta_key does not have any effect on result.
i searched whole google, but didn’t find any solution for my problem. how i should do that :S
Thanks,
A
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.