admin管理员组

文章数量:1415653

$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;

本文标签: How do I show the parent term on a custom taxonomy template (not the ID)