我有一个自定义分类法叫做portfolio-type
. 这个terms = post_type
是portfolio
类别为portfolio-type
我正在尝试获取与当前帖子相同类别的相关帖子
<?php
global $post;
$terms = get_the_terms( $post_id, \'portfolio-type\' );
$terms = $terms[0]->cat_ID;
$myposts = get_posts(array(\'numberposts\' => 5, \'offset\' => 0, \'post_type\' =>\'portfolio\', \'category__in\' => wp_get_post_categories( $post_id, \'portfolio-type\' ), \'post__not_in\' => array($post->ID), \'post_status\'=>\'publish\', \'order\'=>\'ASC\' ));
foreach($myposts as $post) :
setup_postdata($post);
?>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
脚本显示相关帖子,但不显示当前帖子。我使用此代码将相关帖子显示为侧栏菜单。