WordPress.org

Ready to get started?Download WordPress

Forums

Update get_category Function Reference (4 posts)

  1. Gemfruit
    Member
    Posted 11 months ago #

    The function reference page for get_category is incomplete in my eyes, and could use an additional piece of information.

    "Description
    Returns an array of category objects matching the query parameters.

    Arguments are pretty much the same as wp_list_categories and can be passed as either array or in query syntax."

    I was using this code:

    $descendants = get_categories(array('child_of' => 2));

    What's not listed here, is that if there are no posts in a category, those categories will not be returned. I was redoing my theme, and added a bunch of sub-categories, and had no posts currently in those categories, but planned on using them. When attempting to loop through all sub-categories, I was told I had X children, when I knew there were Y. Using my knowledge of programming, I eventually discovered the issue was due to those categories not having posts in them, but that's extremely sloppy documentation, and very important information that should be shared with developer's reading the function reference.

    Please add something along these lines:

    "No results will be returned for categories that do not contain posts." - smoother / more informal wording can be done, but you get the picture.

  2. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 11 months ago #

    The codex is a wiki updated by volunteers. Instead of posting here to suggest improvements, you can help with updating improving it yourself.

    see: http://codex.wordpress.org/Codex:Contributing

  3. Gemfruit
    Member
    Posted 11 months ago #

    I wasn't aware of the update style, noted.

    I'll definitely proceed with that, as I'd love to contribute where possible. While this topic is already open - would my above observation be correct / a sensible addition?

  4. esmi
    Forum Moderator
    Posted 11 months ago #

    Those observations sound correct to me. From what I recall, wp_list_categories() displays exactly the same behaviour and, I think, uses get_categories().

Reply

You must log in to post.

About this Topic