Home › Forums › Front-end Issues › Better query for ACF checkbox values? › Reply To: Better query for ACF checkbox values?
Ah I see..
Well if you check the value in the database I think it will be a serialized array?
If so then IN might not work and you would have to use LIKE.
I’m not an SQL expert but my guess is that IN would look for these specific values exactly (where as LIKE will just look for the value in the whole db input).
Another option might be to change your select values to just numbers from 0 and up?
That way you could easily look for any post with values from 7 – 12 (for example) with the BETWEEN.
$posts = new WP_Query(array(
'post_type' => 'team_member',
'posts_per_page' => 500, //never set to -1 as this is an hazard. what if we at some point has 10 000 posts?
'no_found_rows' => true, //since we dont use pagination we can use this
'update_post_term_cache' => false, //Since we dont use taxonomies we can use this. If you are going to output taxonomies based on this query remove this line.
'meta_query' => array(
array(
'key' => 'groep',
'value' => array(7, 12),
'compare' => 'BETWEEN'
)
)
));
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.