Support » Requests and Feedback » Update get_category Function Reference

  • Gemfruit


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

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator cubecolour



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




    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?



    Forum Moderator

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Update get_category Function Reference’ is closed to new replies.