There are couple of things wrong with your code…
- when filtering it is not
term
that gives the ID of the term, butbusiness
(in this case), since this is the name you’ve provided for the drop-down menu. Replace all instances ofterm
withbusiness
- Taxonomy is not set when filtering. Remove this check from
parse_query
function.
The following worked for me (except I changed ‘listing’ to ‘post’)…
add_action('restrict_manage_posts','restrict_listings_by_business');
function restrict_listings_by_business() {
global $typenow;
global $wp_query;
if ($typenow=='post') {
$taxonomy = 'business';
$term = isset($wp_query->query['business']) ? $wp_query->query['business'] :'';
$business_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("Show All"),
'taxonomy' => $taxonomy,
'name' => 'business',
'orderby' => 'name',
'selected' => $term,
'hierarchical' => true,
'depth' => 3,
'show_count' => true, // Show # listings in parens
'hide_empty' => true, // Don't show businesses w/o listings
));
}
}
add_filter('parse_query','convert_business_id_to_taxonomy_term_in_query');
function convert_business_id_to_taxonomy_term_in_query($query) {
global $pagenow;
$qv =& $query->query_vars;
if ($pagenow=='edit.php' && isset($qv['business']) && is_numeric($qv['business'])) {
$term = get_term_by('id',$qv['business'],'business');
$qv['business'] = ($term ? $term->slug : '');
}
}