最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I show the parent term on a custom taxonomy template (not the ID)?

programmeradmin0浏览0评论
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
echo $term->name; 
echo $term->description; 
echo $term->parent;

Name gives the name.
Description gives the description.
Parent gives the parent ID, not the term.

How do I get the parent term (the word)?

$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
echo $term->name; 
echo $term->description; 
echo $term->parent;

Name gives the name.
Description gives the description.
Parent gives the parent ID, not the term.

How do I get the parent term (the word)?

Share Improve this question edited Aug 17, 2019 at 11:05 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Aug 17, 2019 at 9:01 fastriverfastriver 32 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Again use the get_term_by() function:

$curr_taxonomy = get_query_var('taxonomy');
$term = get_term_by( 'slug', get_query_var('term'), $curr_taxonomy );

if ( $term !== FALSE && $term->parent > 0 )
    $parent_term = get_term_by('id', (int) $term->parent, $curr_taxonomy );
else
    $parent_term = false;
发布评论

评论列表(0)

  1. 暂无评论