Support

Account

Home Forums General Issues Filtering Archives Using Checkbox Custom Fields Reply To: Filtering Archives Using Checkbox Custom Fields

  • Ok, false alarm. The code above was wrong. @elliot Some people over on the Stack Exchange forum are saying I shouldn’t be using a LIKE compare, and an IN instead when using arrays.

    Not sure which is right. But when I try to use an IN compare, I get a blank page when querying my posts.

    add_action('pre_get_posts', 'my_pre_get_posts');
    function my_pre_get_posts( $query ) {
    	if( is_admin() ) {
    		return;
    	}
    	$meta_query = $query->get('meta_query');
            if( !empty($_GET['type']) ) {				
            	$type = explode('|', $_GET['type']);	
    
    	    	$meta_query[] = array(							
                    'key'		=> 'type',
                    'value'		=> $type,
                    'compare'	=> 'IN',
                );
            }
    	$query->set('meta_query', $meta_query);
    	return;	// always return
    }