Skip to content

Instantly share code, notes, and snippets.

@keithdevon
Created October 7, 2014 10:41
Show Gist options
  • Save keithdevon/e3d924d8414e92a601a7 to your computer and use it in GitHub Desktop.
Save keithdevon/e3d924d8414e92a601a7 to your computer and use it in GitHub Desktop.
Allow region query in Relevanssi search
// add region query variable
add_filter('query_vars', 'introduce_region_qv');
function introduce_region_qv($qv) {
$qv[] = 'job_region';
return $qv;
}
// filter relevanssi based on job_region query
add_filter('relevanssi_modify_wp_query', 'region_tax_query');
function region_tax_query($query) {
$tax_query = array();
if (!empty($query->query_vars['job_region'])) {
$tax_query[] = array(
'taxonomy' => 'region',
'field' => 'id',
'terms' => $query->query_vars['job_region']
);
}
if (!empty($tax_query)) {
$tax_query['relation'] = 'AND'; // you can also use 'OR' here
$query->set('tax_query', $tax_query);
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment