Support » Themes and Templates » Category ID

  • 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?

Viewing 1 replies (of 1 total)
  • 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;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Category ID’ is closed to new replies.