【问题标题】:WordPress: get current child taxonomyWordPress:获取当前的儿童分类
【发布时间】:2014-03-27 21:01:54
【问题描述】:

我有一个名为 sm-category 的自定义分类法

区域
- 区域 1
- 区域 2

商店
- 商店 1
- 商店 2

在单个自定义帖子页面中,我只想显示帖子的当前区域,比如说“区域 1”。

get_term_children($term_id, 'sm-category') 将检索包含所有孩子的列表,但我只想要帖子的当前孩子。

有什么解决办法吗?

提前致谢

【问题讨论】:

    标签: php wordpress taxonomy


    【解决方案1】:

    比得到第一个孩子,..

     $subcategorys = get_term_children($term_id, 'sm-category');
     print_r($subcategorys[0]); // The first entry
    

    【讨论】:

    • 啊,谢谢!如果我想获取存档页面中每个帖子的当前区域怎么办?
    • 我的意思是在自定义帖子存档页面中。 get_the_category 仅适用于普通帖子,对吗?不适用于自定义帖子。我错了吗?
    • 它是一样的。帖子 ID 是唯一的。否则,如果您使用自定义分类法,请使用 $categories = get_the_terms( $id, 'TERM NAME' );
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 2020-03-06
    • 2013-12-03
    • 2014-09-05
    相关资源
    最近更新 更多