WordPress.org

Ready to get started?Download WordPress

Forums

get_categories includes categories with drafts (6 posts)

  1. Hiranthi
    Member
    Posted 4 years ago #

    On a client site I am using get_categories to list the categories and also display the number of posts inside each category.

    For some reason it's also displaying categories that have no published posts inside them, but are not empty. Which means: categories with only drafts in them are also getting displayed.

    Ofcourse this shouldn't happen, because those posts are drafts for a reason and visitors get a 'No posts found' message when they click on the categories with only drafts inside them.

    I couldn't find anything about this in the doc's, nor in the forums. Is there a way to exclude those categories from being listed?

  2. Karine
    Member
    Posted 4 years ago #

    Are you using the default parameters for get_categories?

  3. Matt Dunlap
    Member
    Posted 4 years ago #

    do they have subcategories with posts in them? I think that will cause the count to think there are posts where there are any in the parent categories.

    By default, get_categories hides empty categories, and there is something definitely wrong if drafts, or private posts, are getting counted.

  4. Hiranthi
    Member
    Posted 4 years ago #

    I'm using pretty much the default parameters, yes. As I said I couldn't find anything about the drafts related to the parameters.

    The categories - with only drafts in them - that are getting displayed are subcategories.

  5. Hiranthi
    Member
    Posted 4 years ago #

    I've just been told (twitter) this is a common problem (the function calls all cats instead of only those with published posts).

  6. rubenscd
    Member
    Posted 3 years ago #

    I'm having the same problem, has anyone got any solution?

Topic Closed

This topic has been closed to new replies.

About this Topic