0

我想做的是:

  • 在类别 1 的帖子中,每个帖子都有一个标签
  • 现在在另一个类别下的另一个帖子中,我想调用类别 1 中具有相同标签的帖子,cat=1&tag=1例如cat=2&tag=1

这是代码,它不起作用:

<?php

            $t = wp_get_post_tags($post->ID);

                         query_posts( 'cat=45&tag=' . $t. '' );
                                        // The Loop
     while ( have_posts() ) : the_post(); ?>
4

1 回答 1

0

您必须传递tag idinquery_posts并且wp_get_post_tags()返回数组而不是 id 所以最好通过标签实现帖子,您必须传递 tag-id 哪个

<?php

     $t = wp_get_post_tags($post->ID);

     query_posts( 'cat=45&tag=' . $t[0]->term_id. '' );
                                        // The Loop
     while ( have_posts() ) : the_post(); ?>

可以有多个标签,因此您必须循环$t获取所有标签 ID

请参阅本手册wp_get_post_tags

于 2013-08-10T17:24:52.157 回答