get_the_terms在while(have_posts())中复合:the_post()

时间:2019-06-07 03:08:26

标签: wordpress foreach

这是我的代码。这适用于单个帖子,但不适用于类别/搜索循环。

 $terms = wp_get_object_terms( $post->ID , 'people' );
                            foreach ($terms as $term) {
                                $termstr[] = $term->name;
                                $termsslug[] = $term->slug; }


                         if ($termstr !== ''){
                                echo " | By ";
                                $termslink = '<a href="/our-people/'.implode(', ',$termsslug).'" style="color:#666;">'.implode(", ",$termstr).'</a> | '. get_the_date();
                                echo $termslink; 

                            }

这是正在发生的事情

博客帖子A |由PERSON A

BlOG POST B |由PERSON A,PERSON B(只有人B撰写了帖子)

博客发布C |由PERSON A,PERSON B,PERSON A(只有A人撰写了帖子)

应该是...

博客帖子A |由PERSON A

BlOG POST B |由PERSON B

博客发布C |通过PERSON A

0 个答案:

没有答案