Support

Account

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 🙂