I need to get term for current custom post dynamically on single page (for breadcrumbs for example)
I used get_the_terms( $post->ID, ‘curr_post_tax’ )
Or how to get curr_post_tax of current custom post
Or maybe you know others methods
Home>Catalog>Term>CurrProd
2
Answers
The get_the_terms() function returns an array of terms of the specified taxonomy. If you want just the first term from that array then:
Since you ask how to get the term for a Post without knowing the taxonomy in advance, we cannot use these functions because a
$taxonomy
or$taxonomies
parameter is required:Finding a term for a Post without reference to the taxonomy means you could be finding any kind of term:
tag
,category
,custom_taxonomy_1
,custom_taxonomy_2
, etc. If a Post has atag
term and acategory
term, how will your breadcrumb know which term to use without knowing the taxonomy?If you can guarantee that a Post has only one term, and that term is always a valid navigation breadcrumb, then searching without the taxonomy would be safe, and you could try the function below.
Function: get_term_without_taxonomy