douben8492 2018-06-01 18:09
浏览 60
已采纳

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

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

  • 写回答

1条回答 默认 最新

  • doulvli9462 2018-06-01 18:56
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳