Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#55834 closed defect (bug) (duplicate)

wp_list_categories not working correctly since 6.0 upgrade

Reported by: ericcorbett2's profile ericcorbett2 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Since upgrading to version 6.0 the wp_list_categories function is broken, specifically the 'child_of' parameter to $args is ignored.

Change History (8)

#1 @peterwilsoncc
2 years ago

  • Component changed from General to Taxonomy
  • Keywords reporter-feedback added

Hi @ericcorbett2 and welcome to trac!

I have tried to reproduce this problem but am unable to I am afraid.

wp_list_categories( ['child_of' => 2] ); is showing the category I have set up as a subcategory of category 2:

<!-- reformatted for clarity -->

<li class="categories">
        Categories
        <ul>
                <li class="cat-item cat-item-3">
                        <a href="http://wp-dev.local/category/categorized/sub-categorized/">Sub-categorized</a>
                </li>
        </ul>
</li>

By default wp_list_categories() will hide categories that do not contain any posts unless you include the argument 'hide_empty' => false.

Are you able to confirm your child categories have posts or you have included above?


Testing notes

Created two categories

  • Categorized (given the id 2, no parent)
  • Sub-categorized (given the ID 3, categorized as parent)

Ran the following code

  • wp_list_categories( ['child_of' => 2] ) -- no categories display due to lack of posts
  • wp_list_categories( ['child_of' => 2, 'hide_empty' => false] ); -- Sub-categorized shown as expected

Created a post and assigned it to sub-categorized and re-ran the following code

  • wp_list_categories( ['child_of' => 2] ) -- Sub-categorized shown as expected
  • wp_list_categories( ['child_of' => 2, 'hide_empty' => false] ); -- Sub-categorized shown as expected
Last edited 2 years ago by peterwilsoncc (previous) (diff)

#2 follow-up: @ericcorbett2
2 years ago

I think you misunderstand.

I'm talking about invoking wp_list_categories with the &arg array.

And I'm not talking posts, but pages.

Last edited 2 years ago by ericcorbett2 (previous) (diff)

#3 in reply to: ↑ 2 ; follow-up: @ericcorbett2
2 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Replying to ericcorbett2:

I think you misunderstand.

I'm talking about invoking wp_list_categories with the &arg array.

And I'm not talking posts, but pages.

Scrub all that.

There was a coding error on my part that must have lain dormant until the 6.0 upgrade. I'm sorry to have wasted your time.

#4 @SergeyBiryukov
2 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted

No worries, thanks for the follow-up!

#5 in reply to: ↑ 3 ; follow-up: @Quixtar
2 years ago

I'm sorry to bother you, but what was the error in your code?
My wp_list_categories output also is broken after 6.0 update. Even get_terms ignoring 'child_of' parameter, despite the fact that I have set 'hide_empty' to false.

Replying to ericcorbett2:

Replying to ericcorbett2:

I think you misunderstand.

I'm talking about invoking wp_list_categories with the &arg array.

And I'm not talking posts, but pages.

Scrub all that.

There was a coding error on my part that must have lain dormant until the 6.0 upgrade. I'm sorry to have wasted your time.

#6 in reply to: ↑ 5 @ericcorbett2
2 years ago

Replying to Quixtar:

I'm sorry to bother you, but what was the error in your code?
My wp_list_categories output also is broken after 6.0 update. Even get_terms ignoring 'child_of' parameter, despite the fact that I have set 'hide_empty' to false.

Replying to ericcorbett2:

Replying to ericcorbett2:

I think you misunderstand.

I'm talking about invoking wp_list_categories with the &arg array.

And I'm not talking posts, but pages.

Scrub all that.

There was a coding error on my part that must have lain dormant until the 6.0 upgrade. I'm sorry to have wasted your time.

I'm not entirely certain to be honest, as I was using the ob_start() function incorrectly, which complicated things.

What seems to have fixed things though was changing the 'hide_empty' => 1, to 'hide_empty' => false.

Here's my working $args:

    $atts = array(
        'child_of'            => $id,
        'current_category'    => 0,
        'depth'               => 0,
        'echo'                => 0,
        'exclude'             => '',
        'exclude_tree'        => '',
        'feed'                => '',
        'feed_image'          => '',
        'feed_type'           => '',
        'hide_empty'          => false,
        'hide_title_if_empty' => false,
        'hierarchical'        => true,
        'order'               => 'ASC',
        'orderby'             => 'name',
        'separator'           => '',
        'show_count'          => 0,
        'show_option_all'     => '',
        'show_option_none'    => __( 'No categories' ),
        'style'               => 'list',
        'taxonomy'            => 'category',
        'title_li'            => '',
        'use_desc_for_title'  => 1,
    );

Hope that helps.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#7 follow-up: @SergeyBiryukov
2 years ago

  • Resolution changed from worksforme to duplicate

It looks like #55837 is the underlying issue here.

#8 in reply to: ↑ 7 @ericcorbett2
2 years ago

Replying to SergeyBiryukov:

It looks like #55837 is the underlying issue here.

I believe that you're right.

Because of the way I was using the ob_start() function I was inadvertently calling the wp_list_categories() function twice.

Last edited 2 years ago by ericcorbett2 (previous) (diff)
Note: See TracTickets for help on using tickets.