我想获得函数的当前术语。但显然此功能在functions.php
中不起作用。有解决这个问题的主意吗?
$term = get_term_by('name', get_query_var('download_tag'), 'download_tag' );
答案 0 :(得分:1)
<?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 );
}