您的代码错误。我不知道它在您的本地主机中是如何工作的。原因-
您正在呼叫get_terms()
有3个参数,实际接受2个参数。最后一个是额外的其次get_terms()
返回分类法的所有术语,而不是与帖子关联的术语获取您可以使用的帖子的相关术语wp_get_post_terms
.
Usage of wp_get_post_terms
inside WordPress loop-
对于每个帖子,您都可以通过致电
wp_get_post_terms
如下所示-
//Do something if a specific array value exists within a post
$term_list = wp_get_post_terms($post->ID, \'your_taxonomy\', array("fields" => "all"));
// Then you can run a foreach loop to show the taxonomy terms infront.
foreach($term_list as $term_single) {
echo $term_single->slug; //do something here
}
对于环路外部-
// Do something if a specific array value exists within a post
// And somehow you need to get the post ID to pas it to below.
$term_list = wp_get_post_terms($post_id, \'your_taxonomy\', array("fields" => "all"));
// Then you can run a foreach loop to show the taxonomy terms infront.
foreach($term_list as $term_single) {
echo $term_single->slug; //do something here
}
希望这有帮助。