php - WP_Query, using AND with OR -


i have below php:-

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

lets there job 19000 22000 called 'abc', job_salary_from = 19000 , job_salary_to = 22000.

now lets search job between 10000 , 19000, $job_salary_from = 10000 , $job_salary_to = 19999.

this shows when search correct. however, if search job between 20000 , 29999, $job_salary_from = 19999 , $job_salary_to = 29999 nothing showing up.

where job 'abc' should show because $job_salary_to within search bracket.

any appreciated.

i think meta_query syntax not quite right. try this:

$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'     => $job_salary_from,                 'type'    => 'numeric', //for each case                 'compare'   => '>=',             ),             array(                 'key'       => 'job_salary_to',                 'value'     => $job_salary_to,                 'type'    => 'numeric',                 'compare'   => '<=',             ),         ),          array(             'relation' => 'and',             array(                 'key'       => 'job_salary_from',                 'value'     => $job_salary_from,                 'type'    => 'numeric',                 'compare'   => '>=',             ),             array(                 'key'       => 'job_salary_from',                 'value'     => $job_salary_to,                 'type'    => 'numeric',                 'compare'   => '<=',             ),         )     ) ); 

also can try use between, not sure if inclusive or exclusive compare.


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 -