【发布时间】: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
)
【问题讨论】:
-
wp_get_post_termscodex.wordpress.org/Function_Reference/wp_get_post_terms