WordPress Get Current term
Here is a simple function to get the current term who's archive is being displayed.
<?php
/**
* getCurrentTerm
* get the current term which archive is being displayed
* good for categories, tags and custom taxonomies
* @author Ohad Raz
* @return current term object or false is not in a term archive.
*/
function getCurrentTerm(){
if (!is_category() && !is_tag() && !is_tax())
return false;
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
return get_term_by( 'slug', $term_slug, $taxonomyName );
}
Written by raz ohad
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tag
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#