• knoppys

    (@knoppys)


    Hello all

    I am trying to query posts using a bunch of user selectable fields for the values of meta mquery. However my issuesis, if a user leaves a field blank, the query still includes that field. Is there any way I can get the query to simply ignore that field if its empty?
    Thanks

    Heres what I have so far.

    $operatorname = ($_POST['operatorname']);
    $apartmentname = ($_POST['apartmentname']);
    $location = ($_POST['location']);
    $startdate = ($_POST['startdate']);
    $enddate = ($_POST['enddate']);
    $andor = ($_POST['andor']);
    
    $args = array(
    			'post_type' => 'bookings',
    			'meta_query' => array(
    				'relation' => $andorvalue,
    					array(
    						'key' => 'operatorname',
    						'value' => $operatorname,
    						'compare' => '=',
    					),
    					array(
    						'key' => 'apartmentname',
    						'value' => $apartmentname,
    						'compare' => '=',
    
    					),
    			),
    			'date_query' => array(
    			        array(
    			            'after' => $startdate,
    			            'before' => $enddate,
    			        ),
    			),
    		);

The topic ‘Remove empty meta values from meta query’ is closed to new replies.