Category ID (2 posts)

  1. gdnovey
    Posted 8 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. 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