Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have noticed my custom taxonomy filters no longer work in the 3.3.1 admin as per these methods: Adding a Taxonomy Filter to Admin List for a Custom Post Type?

I also discovered that to filter a taxonomy the query string requires both the &taxonomy=whatever and &term=something to be passed. Anyone have any experience in this, and solutions to offer?

Here's some code from the question as an example:

add_action('restrict_manage_posts','restrict_listings_by_business');
function restrict_listings_by_business() {
    global $typenow;
    global $wp_query;
    if ($typenow=='listing') {
        $taxonomy = 'business';
        $business_taxonomy = get_taxonomy($taxonomy);
        wp_dropdown_categories(array(
            'show_option_all' =>  __("Show All {$business_taxonomy->label}"),
            'taxonomy'        =>  $taxonomy,
            'name'            =>  'business',
            'orderby'         =>  'name',
            'selected'        =>  $wp_query->query['term'],
            'hierarchical'    =>  true,
            'depth'           =>  3,
            'show_count'      =>  true, // Show # listings in parens
            'hide_empty'      =>  true, // Don't show businesses w/o listings
        ));
    }
}

and

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['taxonomy']) && $qv['taxonomy']=='business' &&
            isset($qv['term']) && is_numeric($qv['term'])) {
        $term = get_term_by('id',$qv['term'],'business');
        $qv['term'] = $term->slug;
    }
}
share|improve this question
    
So you have a CPT listing, with 'business' taxonomy? What do you mean by it doesn't work - the filter doesn't seem to apply (i.e. all posts still appear)? –  Stephen Harris Feb 21 '12 at 19:48
    
Yes, sorry. I was unclear. All post appear. –  Niels Feb 22 '12 at 0:04
    
Did my solution work for you? –  Stephen Harris Feb 22 '12 at 0:07
add comment

1 Answer

There are couple of things wrong with your code...

  1. when filtering it is not term that gives the ID of the term, but business (in this case), since this is the name you've provided for the drop-down menu. Replace all instances of term with business
  2. 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 : '');
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.