【问题标题】:Wordpress How to get current taxonomy term?Wordpress 如何获取当前的分类术语?
【发布时间】:2019-11-01 23:58:59
【问题描述】:

在单个自定义类型帖子的页面上,我正在尝试获取当前的分类术语

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

current_term、get_query_var('term') 和 get_query_var('taxonomy') 什么都不返回

更新:

$term = get_queried_object(); print_r($term) ; :

    WP_Post Object
(
    [ID] => 324
    [post_author] => 1
    [post_date] => 2019-10-17 14:18:37
    [post_date_gmt] => 2019-10-17 14:18:37
    [post_content] => The performance data 
    [post_title] => Diversified Fund
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => diversified-value-fund
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2019-10-31 20:44:43
    [post_modified_gmt] => 2019-10-31 20:44:43
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://hwcm.my/?post_type=funds&p=324
    [menu_order] => 1
    [post_type] => funds
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

【问题讨论】:

标签: wordpress taxonomy


【解决方案1】:

找到了解决办法:

print_r(get_the_terms(get_the_ID(), 'fund_category'));

给予:

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 5
            [name] => US Equity
            [slug] => us-equity
            [term_group] => 0
            [term_taxonomy_id] => 5
            [taxonomy] => fund_category
            [description] => 
            [parent] => 0
            [count] => 6
            [filter] => raw
            [term_order] => 1
        )

)

【讨论】:

    【解决方案2】:

    你可以使用查询对象

    $term = get_queried_object();
    print_r($term);
    

    【讨论】:

    • 用输出更新了问题
    • $taxonomy_slug = "你的分类"; $terms = get_the_terms( $term->ID, $taxonomy_slug ); if ( !empty( $terms ) ) { foreach ( $terms as $term ) { $out[] = ''. $术语->名称。 "\n"; } 回声内爆(',',$out); }
    • 如果您仍然遇到问题。我可以帮你。你可以加入我的Skype。 Logicdigger@gmail.com
    猜你喜欢
    • 2012-11-25
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多