在归档模板中,我需要提取当前分类的分类标签,我认为应该像这样简单
if (is_tax()) {
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$term_labels = get_taxonomy_labels($current_term);
if (is_super_admin()) {
echo "$taxonomyName, $term_slug<br><pre>";
var_dump($current_term);var_dump($term_labels);
echo "</pre>";
}
}$current_term的转储显示了正确的分类和术语,但是,$term_labels的转储总是显示标签的标签...我似乎找不到我的错误?!
发布于 2020-07-22 13:54:42
get_taxonomy_labels()需要一个WP_Taxonomy对象。您正在向它传递一个WP_Term对象。
尝试:
$tax = get_taxonomy($taxonomyName);
$term_labels = get_taxonomy_labels($tax);https://stackoverflow.com/questions/63027599
复制相似问题