How can I query WordPress Advanced Custom Fields with Search

I am trying to find posts that have a custom field for salary using the WPAS plugin but I am unable to return anything.

The query I am building with WPAS is:

php code

function xpand_job_search_form() {
$args = array();

$args['form'] = array( 
    'action' => home_url('jobs'),
    'class' => 'job-page-form clearfix'
    );

$args['wp_query'] = array('post_type' => 'jobs',
                          'posts_per_page' => 5);


$args['fields'][] = array(
    "allow_null" => "Job Sector",
    'type' => 'taxonomy',
        'format' => 'select',
        'taxonomy' => 'sector',
        );




    $args['fields'][] = array(
        "allow_null" => "Temp/Perm",
    'type' => 'taxonomy',
        'format' => 'select',
        'taxonomy' => 'term',

        );

    $args['fields'][] = array(
    "allow_null" => "Location",
    'type' => 'taxonomy',
        'format' => 'select',
        'taxonomy' => 'location',
        );

    $args['fields'][] = array('type' => 'html',
  'value' => '<label class="blue-text upper-text">Salary</salary>');

    $args['fields'][] = array('type' => 'html',
  'value' => '<div id="slider-range"></div>');


    $args['fields'][] = array(
    'type' => 'meta_key',
        'format' => 'text',
        'attributes' => array('readonly' => 'readonly'),
        'meta_key' => 'salary',
        'compare' => '>=',
  'data_type' => 'ARRAY<NUMERIC>',
  'class' => 'min-field'
        );

    $args['fields'][] = array(
    'type' => 'meta_key',
        'format' => 'text',
        'attributes' => array('readonly' => 'readonly'),
        'meta_key' => 'salary_to',
        'compare' => '<=',
  'data_type' => 'ARRAY<NUMERIC>',
  'class' => 'max-field'
        );


    $args['fields'][] = array('type' => 'html',
  'value' => '<div class="clearfix"></div>');

    $args['fields'][] = array(

    'type' => 'submit',
        'value' => 'Filter results',
        'class' => 'btn btn-orange btn-border upper-text btn-solid btn-slim'

        );



register_wpas_form('headway-refine-form', $args);    
}
add_action('init', 'xpand_job_search_form'); 

The bit that does the meta query (or doesn’t) is the arrays for meta_key

You can test the search here: http://headway.xpandcreative.co.uk/jobs/

As you will see, it doesn’t make any difference what salary range I input, I always get the same results.

Read more here: How can I query WordPress Advanced Custom Fields with Search

Leave a Reply

Your email address will not be published. Required fields are marked *