M
M
Max Zhukov2018-05-08 15:01:39
WordPress
Max Zhukov, 2018-05-08 15:01:39

How to get the bottom level taxonomy on a post page?

category>1category
I need to get 1 category on a post page.
Tried through get_the_terms( get_the_id(), 'category )[1]->term_taxonomy_id;
But on some pages it is at index 0.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-05-08
@MaksZhukov

php.net/manual/en/function.array-reverse.php

$terms = get_the_terms( get_the_id(), 'category' );
$terms = array_reverse( $terms );
echo $terms[0]->term_taxonomy_id;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question