Home Forums General Issues Get Taxonomy Category ID


Get Taxonomy Category ID

  • I’ve created a Taxonomy field for categories. I have return value set as Term Object. I’ve successfully displayed the Category name doing this:

    <?php $term = get_sub_field('category'); ?>
    <h2><?php echo $term->name; ?></h2>

    I’d like to display the category ID as well but can’t seem to find the correct way of going about this.

  • I’ve figured this out. I changed return value to Term ID.

    To display category name, I used this:

    <?php $term = get_term(get_sub_field('category'), 'category'); ?>
    <h2><?php echo $term->name; ?></h2>

    Then if you need to display the ID as well like I did, you just use this:

    <?php echo $term->term_id; ?>

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get Taxonomy Category ID’ is closed to new replies.