Support

Account

Home Forums ACF PRO meta_query value search in checkbox array?

Helping

meta_query value search in checkbox array?

  • I’m trying to do a WP_User_Query with a meta_query checking a checkbox field type against a submitted value from a select field. Code looks like this:

    $sector_field_arr = get_field('sector');
    					
    				$user_query = new WP_User_Query( array( 
    					'role' => 'Member',
    					'meta_key' => 'last_name',
    					'orderby' => 'meta_value',
    					'order' => 'ASC',
    
    					'meta_query' => array(
    					  array(
    						'key' => 'publish_publically',
    						'value' => true
    					  ),
    						array(
    						'key' => $sector_field_arr,
    						'value' => $_POST['sector-select'],
    						'compare' => 'IN'
    					  )
    					)
    
    				) );

    Everything is working except for trying to find the submitted value from the select field ($_POST[‘sector-select’]) in the checkbox array (sector). Any ideas how to find the submitted value in the field array?

  • Turns out I was making it more complicated than it needed to be. This did the trick:

    $user_query = new WP_User_Query( array( 
    					'role' => 'Member',
    					'meta_key' => 'last_name',
    					'orderby' => 'meta_value',
    					'order' => 'ASC',
    
    					'meta_query' => array(
    					  array(
    						'key' => 'publish_publically',
    						'value' => true
    					  ),
    						array(
    						'key' => 'sector',
    						'value' => $_POST['sector-select'],
    						'compare' => 'LIKE'
    					  )
    					)
    
    				) );
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘meta_query value search in checkbox array?’ is closed to new replies.