WordPress.org

Ready to get started?Download WordPress

Forums

Draft posts being counted by wp_list_categories (6 posts)

  1. charlieperrins
    Member
    Posted 3 years ago #

    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?

    Thanks,

    Charlie

  2. David Gwyer
    Member
    Posted 3 years ago #

    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:

    http://codex.wordpress.org/Function_Reference/get_categories

    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.

  3. charlieperrins
    Member
    Posted 3 years ago #

    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?

  4. ragulka
    Member
    Posted 3 years ago #

    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

  5. topsys
    Member
    Posted 3 years ago #

    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?

  6. neomatrix2
    Member
    Posted 2 years ago #

    Hi,

    Has anyone able to figure out the solution yet, I found out this ticket which addresses the issue
    Here is the link:
    http://core.trac.wordpress.org/ticket/14084

    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..

Topic Closed

This topic has been closed to new replies.

About this Topic