Home › Forums › ACF PRO › WP_query using meta_query for an ACF checkbox field › Reply To: WP_query using meta_query for an ACF checkbox field
Hi @ryandorn
I believe you should be able to do it like this:
// Get the selected options
$my_acf_checkbox_field_arr = get_field('my_checkbox');
// Build the meta query based on the selected options
$meta_query = array('relation' => 'OR');
foreach( $my_acf_checkbox_field_arr as $item ){
$meta_query[] = array(
'key' => 'checkbox',
'value' => $item,
'compare' => 'LIKE',
);
}
// args
$args = array(
'numberposts' => -1,
'post_type' => 'my-cpt',
'meta_query' => $meta_query,
);
$the_query = new WP_Query( $args );
I hope this helps 🙂
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.