Support

Account

Home Forums General Issues Multiple value of checkbox in meta_query

Helping

Multiple value of checkbox in meta_query

  • I tried to make a Advanced search form with acf fields and use this query

    if( isset( $_POST['antivirus_threat'] ) && $_POST['antivirus_threat'] == 'on' )
    		$antivirus_filter_args['meta_query'][] = array(
    			'key' => 'antivirus_featured_threat',
    			'value' => 'myitems1',
    			'compare' => 'LIKE'
    		);

    Group field is: antivirus
    Checkbox field is: featured_threat
    items in checkbox : myitems1, myitems2, myitems3, myitems4

    value => array() not worked with ‘LIKE’ in meta_query
    i need to set multiple value of my query because my query take a long time to load posts

    Thanks for any help

  • I don’t see anything wrong with the query based on the information you’ve given for getting posts with one of the values. If you want to do mulitple values at the same time then you have to do

    
    if( isset( $_POST['antivirus_threat'] ) && $_POST['antivirus_threat'] == 'on' )
    		$antivirus_filter_args['meta_query'] = array(
                    'relation' = 'OR,
                    array(
    			'key' => 'antivirus_featured_threat',
    			'value' => 'myitems1',
    			'compare' => 'LIKE'
    		),array(
    			'key' => 'antivirus_featured_threat',
    			'value' => 'myitems2',
    			'compare' => 'LIKE'
    		));
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Multiple value of checkbox in meta_query’ is closed to new replies.