Created
August 25, 2014 17:16
-
-
Save atsea/f4eed60c10068518a61b to your computer and use it in GitHub Desktop.
WordPress: Output Taxonomy Slugs
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
<?php | |
/** | |
* Output Taxonomy Slugs | |
* http://wordpress.org/support/topic/output-taxonomy-slugs | |
*/ | |
// function my_dropdown($name, $taxonomy = 'category') { | |
// $defaults = array( | |
// 'taxonomy' => $taxonomy, | |
// 'id' => $name, | |
// 'name' => $name, | |
// 'show_option_none' => ' - Select - ', | |
// 'selected' => get_query_var($name) | |
// ); | |
// wp_dropdown_categories($defaults); | |
// } | |
add_action('pre_get_posts', 'my_customsearch'); | |
function my_customsearch($query) { | |
if(! $query->is_main_query() || ! $query->is_search ) | |
return; | |
$tax_query = array(); | |
$software_category = (int) get_query_var('software-categories'); | |
$software_platform = (int) get_query_var('software-platform'); | |
$software_audience = (int) get_query_var('software-audience'); | |
// first dropdown | |
if (! empty($software_category) && $software_category > 0) { | |
$tax_query[] = array( | |
'taxonomy' => 'software-categories', | |
'field' => 'slug', | |
'terms' => $software_category | |
); | |
} | |
// second dropdown | |
if (! empty($software_platform) && $software_platform > 0) { | |
$tax_query[] = array( | |
'taxonomy' => 'software-platform', | |
'field' => 'slug', | |
'terms' => $software_platform | |
); | |
} | |
// third dropdown | |
if (! empty($software_audience) && $software_audience > 0) { | |
$tax_query[] = array( | |
'taxonomy' => 'software-audience', | |
'field' => 'slug', | |
'terms' => $software_audience | |
); | |
} | |
if ( sizeof($tax_query) > 0 ) { | |
$tax_query['relation'] = 'AND'; | |
$query->set( 'tax_query', $tax_query ); | |
} | |
} | |
// add my custom query vars | |
add_filter('query_vars', 'mycustom_query_vars'); | |
function mycustom_query_vars($query_vars) { | |
$query_vars[] = 'software_category'; | |
$query_vars[] = 'software_platform'; | |
$query_vars[] = 'software_audience'; | |
return $query_vars; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment