• Having an issue getting my wp_list_categories to display the proper number.

    Basically, I want the list to show 6 top-level categories, sorted by count. However, it appears to be trying to incorporate the subcategories into the number, even if they are not shown. For example:

    <ul><?php wp_list_categories('title_li=&depth=1&child_of=40&orderby=count&order=DESC&number=6'); ?></ul>

    Shows only 2 categories:

    Vegetarian
    Desserts

    Not 6 as specified. If I change depth to 2 or -1, then I see 6 categories, but 4 of them are subcategories of the 2nd:

    Vegetarian
    Desserts
    -Cookies
    -Brownies
    -Blondies
    -Cupcakes

    The 4 subcategories here only have a few posts in them, and therefore should NOT be showing up if it was properly sorting by count.

    Basically I want to ignore the subcategories completely, and only show 6 categories ordered by post count (so the 6 categories with the most posts in them will show). Logically it seems like that is what should happen, but it does not.

    Any ideas why this isn’t working or how to resolve?

Viewing 1 replies (of 1 total)
  • wpismypuppet

    (@wordpressismypuppet)

    If you want to ignore subcategories, then you need to set “hierarchical” to false (it’s true by default). Also beware of “hide_empty” as that is also set to true.

    But in your code, it looks like you have “child_of” set to 40, which means you are already looking at a subcategory set. Is this a typo?

    It would make more sense if you gave us an example of how the structure is set up in the back end, and how you want it to look with this code. If you are looking at getting the top level items that are children of 40, then it’s a different situation from getting top level items that are not children of anything.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_list_categories show 6 posts ordered by count’ is closed to new replies.