How do i make the relation of a drop down field to use the OR logic instead of AND in php wordpress

Viewed 24

Hi I'm currently trying to edit the relation of the City dropdown which you can find on this page to use the the OR logic like on the first field Region

I have attempted to change the AND to OR through the function.php file like below but this didn't work

function filter_florida_location() {

     ob_start();
        
        $tax_query = array('relation' => 'AND');
        if (isset($_POST['region']) && !empty($_POST['region']))
        {  
            $tax_query[] =  array(
                    'taxonomy' => 'region',
                    'field'    => 'term_id',
                    'terms'    =>  $_POST['region'],
                    //'operator' => 'IN',
                );
        } 
        
        
        if (isset($_POST['city']) && !empty($_POST['city']))
        {   
            foreach($_POST['city'] as $key => $val){
            $tax_query[] = array('relation' => 'OR');   
            $tax_query[][] =  array(
                    'taxonomy' => 'city',
                    'field'    => 'term_id',
                    'terms'    => array($val),
            );
            }   
        } 

Thank you in advance!!

1 Answers

You have to change this

$tax_query[] = array('relation' => 'OR');

to

$tax_query['relation'] = 'OR';
Related