I’m trying to list an archived of queried custom post types named ‘jobs’, each with a custom field of ‘minimum_salary’ and ‘maximum_salary’.

On the previous search page the user enters two values in the search (‘min-salary’ & ‘max’salary’), which are added to the URL of the archive page.

I want to be able to display ALL jobs that have a ‘minimum_salary’ AND ‘maximum_salary’ BETWEEN the min and max salary var the user entered on the previous page.

See below for my code so far, thanks for the help.

<?php

$minSalaryVar = get_query_var('min-salary');
$maxSalaryVar = get_query_var('max-salary');

$taxArgs = array();


if ($minSalaryVar && $maxSalaryVar) {
  $taxArgs[] = array(
    'meta_query' => array(
      'relation' => 'AND',
      array(
        'key' => 'minimum_salary',
        'value' => array($minSalaryVar, $maxSalaryVar),
        'compare' => 'BETWEEN',
        'type' => 'numeric'
      ),
      array(
        'key' => 'maximum_salary',
        'value' => array($minSalaryVar, $maxSalaryVar),
        'compare' => 'BETWEEN',
        'type' => 'numeric'
      ),
    )
  );
}




   if ($taxArgs) {
  $args = array (
  'tax_query' => $taxArgs,
  );

  $argsNew = array_merge( $wp_query->query_vars, $args );
  query_posts( $argsNew );
} ?>

Read more here: WordPress query for Custom Field number BETWEEN two query variables


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: