Created
June 13, 2012 07:47
-
-
Save foxinni/2922611 to your computer and use it in GitHub Desktop.
Modify wp_dropdown_categories() to support taxonomy->slug in select output, and not taxonomy->id.
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 | |
/* | |
Background: My company post type needed a filter added via the 'restrict_manage_posts' action, and I needed to modify the wp_dropdown_categories to output the taxonomy slug into the <option value="..."> instead of the taxonomy ID. The taxonomy being 'industry'. | |
The SH_Walker_TaxonomyDropdown() can be found here: https://gist.github.com/2902509 | |
*/ | |
function restrict_listings_by_taxonomy() { | |
global $typenow; | |
global $wp_query; | |
if ($typenow == 'company' ) { | |
$taxonomy = 'industry'; | |
$current_taxonomy = get_taxonomy($taxonomy); | |
wp_dropdown_categories( | |
array( | |
'walker'=> new SH_Walker_TaxonomyDropdown(), | |
'value'=>'slug', | |
'show_option_all' => __("Show All {$current_taxonomy->label}"), | |
'taxonomy' => $taxonomy, | |
'name' => 'industry', | |
'orderby' => 'name', | |
'selected' => $wp_query->query['term'], | |
'hierarchical' => true, | |
'depth' => 3, | |
'show_count' => true, // Show # companies in parents | |
'hide_empty' => true, // Don't show companies w/o listings | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, thanks for sharing.