restrict_manage_posts not working in 3.3.1

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?

Read More

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;
    }
}

Related posts

Leave a Reply

1 comment

  1. 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 : '');
        }
    }