php - WP_Query - Using multiple AND / OR -


i have below php code:-

    $args = array(         'posts_per_page'=> -1,         'post_type'     => 'jobs',         'order'             => 'asc',         's' => $search_field,         'meta_query'    => array(             'relation' => 'or',             array(                 'relation' => 'and',                 array(                     'key'       => 'job_salary_to',                     'value'     => array($job_salary_from,$job_salary_to),                     'type'    => 'numeric',                     'compare'   => 'between',                 ),             ),             array(                 'relation' => 'and',                 array(                     'key'       => 'job_salary_from',                     'value'     => array($job_salary_from,$job_salary_to),                     'type'    => 'numeric',                     'compare'   => 'between',                 ),             )         )        ); 

this check see if search between minimum , maximum values works okay.

now want add further query check if matches job sector, e.g. added following below 'meta_query':-

            'relation' => 'and',             array(                 'key'       => 'job_sector',                 'value'     => 'finance',                 'compare'   => 'like',             ), 

however, seems ignoring above , i'm not sure why. appreciated!

so looks now:-

    <?php     $args = array(         'posts_per_page'=> -1,         'post_type'     => 'jobs',         'order'             => 'asc',         's' => $search_field,         'meta_query'    => array(             'relation' => 'or',             array(                 'relation' => 'and',                 array(                     'key'       => 'job_salary_to',                     'value'     => array($job_salary_from,$job_salary_to),                     'type'    => 'numeric',                     'compare'   => 'between',                 ),             ),             array(                 'relation' => 'and',                 array(                     'key'       => 'job_salary_from',                     'value'     => array($job_salary_from,$job_salary_to),                     'type'    => 'numeric',                     'compare'   => 'between',                 ),             ),         ),           'relation' => 'and',         array(             'key'       => 'job_type',             'value'     => $job_type,             'compare'   => 'like',         ),         array(             'key'       => 'job_location',             'value'     => $job_location,             'compare'   => 'like',         )     );      $fetch_jobs = new wp_query( $args );?> 

the job_type / job_location conditions should put under 'meta_query' guess:

'meta_query' => array(     'relation' => 'and',     array(         array(             'key'       => 'job_type',             'value'     => $job_type,             'compare'   => 'like',         ),         array(             'key'       => 'job_location',             'value'     => $job_location,             'compare'   => 'like',         ),     ),     array(         'relation' => 'or',         array(             'relation' => 'and',             array(                 'key'       => 'job_salary_to',                 'value'     => array($job_salary_from,$job_salary_to),                 'type'    => 'numeric',                 'compare'   => 'between',             ),         ),         array(             'relation' => 'and',             array(                 'key'       => 'job_salary_from',                 'value'     => array($job_salary_from,$job_salary_to),                 'type'    => 'numeric',                 'compare'   => 'between',             ),         ),     ) )         

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -