WordPress.org

Ready to get started?Download WordPress

Forums

Category ID (2 posts)

  1. gdnovey
    Member
    Posted 6 years ago #

    I'd like to find out the id of categories. There used to be a tag the_category_id but it is deprecated. What do I use in it's place?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    The question is: What do you have already? You want to find out the ID of a category, but what are you starting out with?

    Do you want the categories for a post? Posts can have multiple categories, you know. If so, you'd use get_the_category() to get the array of category objects, and then look at their term_id values. Like so (in the Loop):

    $cats = get_the_category();
    foreach ($cats as $cat) {
    echo $cat->term_id;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags