Support » Fixing WordPress » Getting category descriptions from names, or ids from names

  • As the title says, I need either a way to call category_description using the category’s name, or to get the category’s ID from the name.

Viewing 6 replies - 1 through 6 (of 6 total)
  • How to do this is very dependent on *where* you’re doing it. I noted here that $cat holds the category ID when a category query occurs. If that’s not enough, spell out what you’re trying to accomplish.

    EDIT: Note also the suggestion I give here for collecting user data on author queries:

    works the same for a category’s data on a category query.

    That works perfectly, thanks! I’ve never seen it anywhere in the codex, though.

    Wait. No it doesn’t. It gets the ID OK, but it still has the kind of problem mentioned in the other thread:
    “but then if the most recent post is belonged to a child category then the ID would be the child’s ID.”

    That’s the problem. I think it is because the sidebar is done after the loop, so $cat holds the ID of the last category of the last post on the page.

    However, single_cat_title('', false) will get the proper category name I want, which is why I asked whether there was a way to convert that name to an ID.

    Try sticking:


    in before the global scoping of $wp_query, etc. and see if that clears things up.

    Eek. It did work originally, I just messed up. I’ll still remember rewind_posts in case I need it.

    Messed up? Hey, we don’t do that around here…

    {looks around sheepishly}

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting category descriptions from names, or ids from names’ is closed to new replies.