Getting category descriptions from names, or ids from names (7 posts)

  1. maestrosync
    Posted 10 years ago #

    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.

  2. Kafkaesqui

    Posted 10 years ago #

    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.

  3. maestrosync
    Posted 10 years ago #

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

  4. maestrosync
    Posted 10 years ago #

    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.

  5. Kafkaesqui

    Posted 10 years ago #

    Try sticking:


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

  6. maestrosync
    Posted 10 years ago #

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

  7. Kafkaesqui

    Posted 10 years ago #

    Messed up? Hey, we don't do that around here...

    {looks around sheepishly}

Topic Closed

This topic has been closed to new replies.

About this Topic