How do I get current taxonomy term id on wordpress

2019-03-07 19:16发布

I've created a taxonomy.php page in my wordpress template folder, I would like to get the current term id for a function. How can I get this?

get_query_var('taxonomy') only returns the term slug, I want the ID

8条回答
放荡不羁爱自由
2楼-- · 2019-03-07 19:47
<?php 
$terms = get_the_terms( $post->ID, 'taxonomy');
foreach ( $terms as $term ) {
    $termID[] = $term->term_id;
}
echo $termID[0]; 
?>
查看更多
狗以群分
3楼-- · 2019-03-07 19:53

Nevermind! I found it :)

get_queried_object()->term_id;
查看更多
登录 后发表回答