Support » Fixing WordPress » Bug in get_nested_categories

  • I posted that there is a bug in drop_down_cats, which there isn’t. The problem is in drop_down_categories, which uses get_nested_categories.
    It only works if the child categories were created after the parent categories. If you want to put your categories under a new top-level category, it doesn’t work, ie. not all categories are displayed.
    This can be easily demonstrated as follows.
    create cat0, parent none
    create cat1, parent none
    create cat2, parent none
    edit cat1 and make cat2 its parent
    edit cat0 and make cat1 its parent
    now go into write or edit post, and you won’t see cat0.
    Is this a known bug, and is there a fix ?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Mark (podz)


    Support Maven

    You could browse mosquito:
    and if it’s not there, I’m sure adding it would be appreciated.

    LEt me guess… .the new parent cat has no posts in it. By default, WP sets “hide_emtpy” to true…. which means that unless your parent cat has at least one post in it, the child cats will be hidden as well.
    1) Put one post in the parent cat.
    2) Change the hide_empty parameter to False, to allow empty categories to show.

    None of the cats had any posts in, that’s irrelevant. I’m not talking about the display of the cats in the blog.
    I’m talking about the display of the cats in the siderbar in admin mode when you create or edit a post.
    There is no hide_empty parameter to dropdown_categories or get_nested_categories.

    Any category whose grandparent’s cat_ID is greater than its own cat_ID will never be seen again in the admin sidebar category listing in write or edit post.
    This is what is making WP difficult for us to use at present.
    I’ve been staring at the code in get_nested_categories for days, looking for an easy fix.

    Well, the problem is that the code is designed to only traverse TWO levels, you have three…..
    … cat1
    …… cat0
    I’ve often wondered about that myself, but didn’t give it much thought since I didn’t have need for it.
    The function isn’t recursive at all. I simply gets a list of categories that have parent id = 0 (that would mark them as parent cats), then loops through each of those looking for child cats with a parent ID of the current parent cat. It doesn’t then loop again through the list. That’s where the “problem” is. Whether or not it’s a bug, or if it’s by design I don’t know.
    Now, before you say “but it let me…” blah, blah, blah, and a gun lets me shoot myself, doesn’t mean I’m going to do it. Should it have limited the parent list? *shrug* Do I have a solution? Nope.

    Thanks. Atleast I know I’m not losing it. Is there supposed to be a limit on the number of nested categories ? I couldn’t find a limit in the docs.
    I know we need atleast 4. We are using WP as a full blown Content Management System. Clearly WP wasn’t designed to be that, but we like WP because
    1. A lot of the stuff is there anyway.
    2. We get the source, so we can fiddle with it.
    But we don’t want to fiddle too much, or we’ll have problems each time there is a new WP release.
    One of my colleagues said if you write recursive code you can dela with any number, but I don’t think it’s that easy. Clearly I’ve got to write a fix for this. Who would know if such a fix should be incorarated into WP, or if it is ‘out of scope’ for WP.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Bug in get_nested_categories’ is closed to new replies.