Support » Fixing WordPress » Draft posts being counted by wp_list_categories

  • Hi,

    I’m using wp_list_categories to pull in a list of custom taxonomy terms into a sidebar. The terms (named ‘Keywords’) are being pulled in with the following code:

    <?php wp_list_categories('taxonomy=keywords&hide_empty=1&show_count=1&title_li='); ?>

    The problem is that the function is counting posts that are currently marked with a ‘draft’ publish status. These posts are showing in the count figures so the ‘hide_empty’ parameter is not working as expected.

    Has anyone else had the same problem? is there a workaround or a fix out there?



Viewing 5 replies - 1 through 5 (of 5 total)
  • Strange, but there seems no easy way to filter only published posts for the post count. The only option that I can see is if you use the get_categories() function:

    and loop through the returned array and update the post count with the ‘proper’ post count which you would have to obtain manually. Not an easy solution really, but possible.

    It’s a weird one isn’t it?

    Thanks for the suggestion I’ll look into it and see if the extra DB requests etc feel worth it – if not I’ll just ditch the count from the template!

    Is this the sort of thing that could/should be submitted as a bug or a feature request or something? If so does anyone know where I would go about submitting it?

    I’d say its a feature/bug
    I would suggest that there should be two counts: the total count (like we have right now) and a count that includes only published posts

    I’m having the same problem and it also occurs with get_categories. What is really annoying is that the category shows up, even when hide_empty is set and all the posts in the category are drafts, meaning that it will just send you to a “sorry no posts” kind of page.

    Does anyone have a solution for this issue, it would be much appreciated?


    Has anyone able to figure out the solution yet, I found out this ticket which addresses the issue
    Here is the link:

    the patch in this ticket dsnt seem to work.

    How do i count only published posts using wp_list_categories or is there any alternative..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Draft posts being counted by wp_list_categories’ is closed to new replies.