Created
October 7, 2014 10:41
-
-
Save keithdevon/e3d924d8414e92a601a7 to your computer and use it in GitHub Desktop.
Allow region query in Relevanssi search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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