Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foxinni/2922611 to your computer and use it in GitHub Desktop.
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.
<?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
)
);
}
}
@whyisjake
Copy link

This is great, thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment