Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I wanted to get the category ID for the current post, I would use something like this:

<?php foreach((get_the_category()) as $category) { echo $category->cat_ID . ' '; } ?>

How can I do the same for a a term ID from a specific Taxonomy?

share|improve this question
add comment

2 Answers

See get_the_terms(), you'd do something like so:

foreach((get_the_terms($post->ID) as $term) { echo $term->term_id. '<br/>'; }
share|improve this answer
add comment

Thanks helgatheviking, it didn't work as is but you definitely set me on the right path. I got it working by doing the following:

<?php foreach((get_the_terms($post->ID, 'your-taxonomy-here')) as $term) { echo $term->term_id. ''; } ?>

Replace "your-taxonomy-here" with your own and your ready to go.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.