Another short snippet-style article for today; How do you get the current term or taxonomy object in WordPress?
Sometimes, when developing plugins or themes, you need to get more details on the current term page the website visitor is looking at. We can load term meta by using
get_term_meta functions, but what if we want to get general information about the term?
We can use the
get_queried_object function, like below:
$queried_object = get_queried_object(); $term_id = $queried_object->term_id;
See al the information the object contains by using:
And get specific meta values from the term, by using:
$meta_key = get_term_meta($term_id, 'field_key', true);
Leave a Reply