Support

Account

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

  • @elliot Do you think this has anything to do with the serialized data the Checkbox Field outputs?

    Some of my books are assigned to multiple Book Types, like so:

    Book Title: Mums and Babies
    Book Type:

    • Women
    • Babies
    • Children

    Wondering if this is what’s causing the issue.

    This is where I’m at currently:

    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'); // get original meta query
            
            if( isset($_GET['type']) ) {                        
            
            $type = '"' . $_GET['type'] . '"';      
    
            $meta_query[] = array(
                'key'       => 'type',
                'value'     => $type,
                'compare'   => 'LIKE',
            );
        }
        $query->set('meta_query', $meta_query); // update the meta query args
        return; // always return
    }

    Works with one value, but not multiple values (.com/?type=women,babies):