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.

The code below if from my WP plugin which gives a filtered listing of categories excluding the "uncategorized" category from display. However, when the user chooses "Show Hierarchy" from the widget setup options, the resulting display includes "uncategorized".

Given that I've placed 'exclude_tree' => 1 into the $cat_args array. What am I missing?

class My_Widget_Categories extends WP_Widget {

    function My_Widget_Categories() {
        $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "filters out uncategorized categories" ) );
        $this->WP_Widget('my_categories', __('my Categories'), $widget_ops);
    }

    function widget( $args, $instance ) {
        extract( $args );
        $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title']);
        $c = $instance['count'] ? '1' : '0';
        $h = $instance['hierarchical'] ? '1' : '0';
        $d = $instance['dropdown'] ? '1' : '0';

        echo $before_widget;
        if ( $title )
            echo $before_title . $title . $after_title;
            $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'exclude_tree' => 1);
        if ( $d ) {
            $cat_args['show_option_none'] = __('Select Category');
            wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
share|improve this question
    
The code does not look complete, so it's hard to spot the error. –  hakre Nov 23 '10 at 15:04
add comment

1 Answer

up vote 1 down vote accepted

It's hard to say from your code. The exclude_tree parameter of wp_dropdown_categories() is pretty undocumented in codex. It's making use of get_categories() which does not list it at all.

If you don't have children within that category, you can consider to use the exclude parameter instead / additional. Just give it a test if that works. This might save you the hassle to deal with some bugs in wordpress in the end. Wordpress is not very well in handling hierarchy over the last years.

Some background info: Beta 2.8.2 - wp_list_categories buggy hierarchy - Ticket #9999; With wp_list_categories child categories not excluded when parents are excluded - Ticket #8614

share|improve this answer
    
thanks, there will definitely be child nodes off "uncategorized". It seems that the exclude_tree works on everything except the hierarchical display. With that said, adding $cat_args['exclude'] = 1 does the trick! –  Scott B Nov 23 '10 at 15:14
    
uncategorized definitely has children and I was able to get exclude to work nonetheless. At least this is how it works on 3.01 –  Scott B Nov 23 '10 at 15:30
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.