WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_list_categories does not accept 'exclude' anymore. (14 posts)

  1. neXorianus
    Member
    Posted 5 months ago #

    Hello,

    I ran into issues today after updating to WP 3.7.

    I have a wp_list_categories() call in my template with following parameters:

    $args = array(
        'orderby' => 'name',
        'order' => 'ASC',
        'exclude' => get_excluded_cats(), // e.g. 4,11
        'hide_empty' => 1,
        'title_li' => '',
        'walker' => new Category_Color_Walker()
    );

    get_excluded_cats() returns a comma separated list of categorie ids.

    The custom Walker is also not really special:

    class Category_Color_Walker extends Walker_Category
    {
    
        function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0)
        {
            extract($args);
            $cat_name = esc_attr($category->name);
            $cat_name = apply_filters('list_cats', $cat_name, $category);
            $link = '<a href="' . esc_url(get_term_link($category)) . '"';
    
            if(function_exists('get_tax_meta')){
                $css = '';
                if(get_tax_meta($category->term_id, 'ba_background_color_field_id') && get_tax_meta($category->term_id, 'ba_background_color_field_id') != '#')
                    $css .= 'background-color:' . get_tax_meta($category->term_id, 'ba_background_color_field_id') . ';';
    
                if( !empty($css) )
                    $link .= ' style="' . $css . '"';
            }
            $link .= '><span>' . $cat_name . '</span></a>';
    
            if ('list' == $args['style']) {
                $output .= "\t<li";
                $output .= ">$link\n";
            } else {
                $output .= "\t$link<br />\n";
            }
        }
    }

    Sadly the the categories with the corresponding ID's still show up.
    Is there anything I'm doing wrong, or anything that I need to change?

    Thanks in advance,
    ~neX

  2. FoToRo
    Member
    Posted 5 months ago #

    I have exactly the same problem after installing 3.7 :(

  3. neXorianus
    Member
    Posted 5 months ago #

    a quick fix is to add this to your Custom Walkers start_el:

    extract($args);
    //quick fix because exclude stopped working in WP 3.7
    $exclude = explode(',',$exclude_tree); //if $exclude_tree does not work try $exclude
    if (!in_array($category->term_id, $exclude)) {
        //do the usual walker stuff
    }
  4. FoToRo
    Member
    Posted 5 months ago #

    Thanks, but I don't use a walker, I just use the plain function.

    This is the contents of my $args:
    orderby=name&order=asc&depth=3&exclude=9,1,5&hide_empty=1&title_li=&echo=0

    It worked before installing 3.7. Now it just ignores the exclude and displays all categories.

  5. udobnoposvetu
    Member
    Posted 5 months ago #

    I also use this, but I also had other 3.7 problems so I am back on 3.61... Seams this upgrade will be a bit problematic..

  6. FoToRo
    Member
    Posted 5 months ago #

    I'm back on 3.6.1 too.

  7. msmgking
    Member
    Posted 5 months ago #

    Has anyone had any luck finding a work around for this yet? I'm searching and trying what I can, really hate to downgrade all of my sites.

  8. sichtkunst
    Member
    Posted 5 months ago #

    I'm back to 3.6.1 too. Anyone a workaround?

  9. Mike Bijon
    Member
    Posted 5 months ago #

    I've added a Trac ticket for this:
    * http://core.trac.wordpress.org/ticket/25710

  10. Mike Bijon
    Member
    Posted 5 months ago #

    There's a one line fix in Trac that you can make manually (recommended to understand apply I g SVN diff's though), or wait for 3.7.2 and this will be included:
    * http://core.trac.wordpress.org/ticket/25710#comment:9

  11. joynic
    Member
    Posted 5 months ago #

    this is my solution, replace <?php wp_list_categories();?> with:

  12. neXorianus
    Member
    Posted 5 months ago #

    There's a one line fix in Trac that you can make manually (recommended to understand apply I g SVN diff's though), or wait for 3.7.2 and this will be included:
    * http://core.trac.wordpress.org/ticket/25710#comment:9

    seems to be the best solution, because after the update to 3.7.2 your changes in the core files to fix this bug will be overwritten with the real fixing data.

    anny other (non core) "hotfix" will stay even after the update, and might slow down/cause problems with your wordpress.

  13. joynic
    Member
    Posted 5 months ago #

    please try this

    <ul>
    <?php foreach(get_categories("orderby=name&orderby=count&order=DESC&exclude=14,1,3,4,5,9&hide_empty=0") as $category) {echo '<li class="cat-item cat-item-'.$category->cat_ID.'"><a href="'.get_category_link($category->cat_ID).'" title="'.$category->category_description.'">'.$category->cat_name.'</a></li>';} ?>
    </ul>

    replace 'exclude=14,1,3,4,5,9' with yours

  14. neXorianus
    Member
    Posted 5 months ago #

    this has been fixed in 3.7.1 see http://codex.wordpress.org/Version_3.7.1

Reply

You must log in to post.

About this Topic