• Hi,
    I’m using wp_list_categories to list categories from default taxonomy ‘category’ with hide_empty=1.
    However it returns all the categories regardless of the posts status: it displays categories with only unpublished posts in it, linking to a “sorry no posts” page…
    This is quite gamebreaking to me.
    I found this http://core.trac.wordpress.org/ticket/14084 but it refers to custom taxonomies (and it’s still unresolved…)

    Anyone care to help? 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • wpismypuppet

    (@wordpressismypuppet)

    Long story short… wp_list_categories, when broken down, used get_terms as a root of how it gets categories and the term information associated with it. Since get_terms is used for a number of other methods, it is not applicable for code to be changed to exclude draft, or non-published posts in this code.

    One way around the issue (which is probably more work than it’s worth, and might even tax the server too much to bother with) is to create a custom Walker class that extends Walker_Category. While going through each item, you’ll need to do a get_posts for each term and query for posts that are published. If you get any number of posts greater than 0, display that term. Otherwise skip it and move on.

    Again, complicated but doable… here is an article of someone extending the class in a different way… not applicable to your question, but it at least gives you instructions on how to create a Walker and apply it.

    Thread Starter Antonello Crescenzo

    (@hedgehogoo)

    Wow, this is disappointing! 😀
    Maybe I’m just better off figuring out some workaround, I don’t really have that much time to spend on such a simple function…
    Well, thank you for your time!

    PS: I’m still curious tho, I guess you forgot to link the article you mentioned?

    wpismypuppet

    (@wordpressismypuppet)

    I did forget the link… terribly sorry about that. Here it is:

    http://scribu.net/wordpress/extending-the-category-walker.html

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_list_categories and unpublished posts’ is closed to new replies.