I need to display the current term in my custom taxonomy in a single post.
example:
- My custom taxonomy is products and term of them is product-1, product-2 and products-3.
- My post is assigned to product-2
- And I want to print the current products = products-2 in my post
In fact, I need a function like WordPress’s the_category();
but for my taxonomy like the_customtaxonomy();
UPDATE :
in facts i know i need to get id of this becuse i need to show a icon for this in my single , for example a function like the_category_ID();
You can use
get_the_term_list()
:tanks for answer from my friend , i find it for show slug of my taxonomy
and
but it return all term in my taxonomy and i need to return current term in my taxonomy ..
UPDATE :
i finaly find this and add if for empty terms and works
I found it:
It gets all terms in my custom taxonomy and I need to get current term.
You need to use
wp_get_object_terms()
wp_get_object_terms( $object_ids, $taxonomies, $args )
Taking what user3208 coded, I have added a bit of code that adds the URL to the Term. Hope that helps someone out.
A bit of update on the subject as this question is about 11 years old, and nobody mentioned it.
You can use
get_query_var()
.Instead of doing a other query, we’re just fetching the term from the current one. Then we can echoed it out on the front-end.