按分类分类的相关帖子不起作用,可能是什么原因?

时间:2019-03-23 作者:starspro

每个人分类法的相关帖子不起作用,原因可能是什么?

$tax_IDs = array();
foreach ($tags as $tag) {
    $tax_IDs[] = $tag->ID;
}

$args = array(
  \'post_type\' => \'films\',
  \'post__not_in\' => array($post->ID),
  \'showposts\'=> 3,
  \'tax_query\' => array(
        array(
            \'taxonomy\' => \'actors\',
            \'field\' => \'id\',
            \'terms\' => $tax_IDs
        )
    )
);
 $my_query = new wp_query($args);
 if( $my_query->have_posts() ) {

 echo \'<div class="related-slider">\';
        while ($my_query->have_posts()) {
            $my_query->the_post();
        ?>
            <div><?php the_title(); ?></div>       
        <?php
        }
        echo \'</div>\';
    }
 wp_reset_query();

1 个回复
SO网友:Michelle

您的tax\\u查询使用了无效的field 类型尝试:

$args = array(
  \'post_type\' => \'films\',
  \'post__not_in\' => array($post->ID),
  \'showposts\'=> 3,
  \'tax_query\' => array(
        array(
            \'taxonomy\' => \'actors\',
            \'field\' => \'term_id\',
            \'terms\' => $tax_IDs
        )
    )
);
请参见Taxonomy Parameters 如果不可行,请查询更多选项。

相关推荐