我正在使用本教程:https://www.wpexplorer.com/related-posts-category/
上面的教程非常适合显示该类别中的相关帖子,但是我有一个名为游戏的分类法,并且相关帖子不会显示。我猜想是因为它属于自己的特殊分类法,而wp_query无法识别它。如何包含当前代码以检索分类法游戏?
<?php
/**
* Module Name : Related Posts
*
*/
$args = array (
'posts_per_page' => 3,
'post__not_in' => array( get_the_ID() ),
'no_found_rows' => true,
);
$cats = wp_get_post_terms( get_the_ID(), 'category' );
$cats_ids = array();
foreach( $cats as $wpex_related_cat ) {
$cats_ids[] = $wpex_related_cat->term_id;
}
if ( ! empty( $cats_ids ) ) {
$args['category__in'] = $cats_ids;
}
$wpex_query = new wp_query( $args );
?>