在分类页面上显示当前分类的自定义字段

问题描述:

I have a custom taxonomy called Books with 2 custom taxonomy fields. One is called book_tagline and other called book_short_desc

So for example If I have a Books Category like School Books and the 2 custom fields contains values as

book_tagline = 12th grade all school books book_short_desc = we have all 12th grade school books...

On the Books Category page I would like to display the above 2 custom fields

Here is my code but its not displaying the values

$termcat = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
$icat_id = $termcat->term_id;
$icat_tag = get_term_meta($icat_id, '_pc_ccat_tagline');
 $icat_desc = get_term_meta($icat_id, '_pc_ccat_desc');

The above code is not inside a loop. But the code is in the taxonomy-books template page

Thanks

我有一个名为Books的自定义分类,包含2个自定义分类字段。 一个名为book_tagline,另一个名为book_short_desc p>

例如,如果我有一个类似于学校图书的图书类别,则2个自定义字段包含的值为 p>

book_tagline = 12年级所有学校的书籍 book_short_desc =我们有所有12年级的学校书籍... p>

在图书类别页面上,我想显示以上2个自定义字段 p>

这是我的代码,但它没有显示值 p>

  $ termcat = get_term_by('slug',get_query_var('term'),get_query_var('  taxonomy')); 
 $ icat_id = $ termcat-> term_id; 
 $ icat_tag = get_term_meta($ icat_id,'_ pc_ccat_tagline'); 
 $ icat_desc = get_term_meta($ icat_id,'_ pc_ccat_desc'); 
   pre> 
 
 

上面的代码不在循环中。 但是代码在分类学书籍模板页面中 p>

谢谢 p> div>

Try below code

$pc_ccat_tagline = get_term_meta( get_queried_object_id(), '_pc_ccat_tagline', true);

$pc_ccat_desc = get_term_meta( get_queried_object_id(), '_pc_ccat_desc', true);

Do not forget to do echo.

If this code does not work than just pass true in your code

$icat_desc = get_term_meta($icat_id, '_pc_ccat_desc',true);