在一篇文章中,如何获得标签slug&用于该特定帖子的标签的标签ID。
例如;我有一个帖子" Hello World!"标记在"我的帖子"。如何获得slug" my-post"在" Hello World!"帖子页面(即; single.php文件)。
答案 0 :(得分:1)
$terms = get_the_terms( $post->ID, 'post_tag' );
if ( !empty( $terms ) ){
// get the first term
$term = array_shift( $terms );
echo $term->slug;
}
参考:https://wordpress.stackexchange.com/questions/130947/get-term-slug-of-current-post