Php wordpress自定义类别页面中的_post方法不显示顶部查看的帖子
我看过的帖子最多(在客户分类中),在主页中我添加了这个小部件,它工作得很好,在详细页面中也很好,但在分类页面中,同一个小部件的行为很奇怪Php wordpress自定义类别页面中的_post方法不显示顶部查看的帖子,php,wordpress,Php,Wordpress,我看过的帖子最多(在客户分类中),在主页中我添加了这个小部件,它工作得很好,在详细页面中也很好,但在分类页面中,同一个小部件的行为很奇怪 $r = new WP_Query( array( 'tax_query' => array( 'relation' => 'OR', array( 'ta
$r = new WP_Query( array( 'tax_query' =>
array(
'relation' => 'OR',
array(
'taxonomy' => 'custcategory',
'field' => 'term_id',
'terms' => array(10)),
),
'category__in'=>array(10),
'post_type'=> $post_type ,
'posts_per_page' => $number,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC' ) );
if ($r->have_posts()) :
// Enters this block in home page and detail page
while ( $r->have_posts() ) : $r->the_post();
else:
// Enters this block in category page
有人知道为什么会出现这种奇怪的行为吗?也许您有一些影响类别页面的筛选器,请将其添加到您的查询参数中:
'suppress_filters' => true
您也可以尝试在主查询之后添加wp\u reset\u query(),但这不是必需的,因为您正在声明一个新的wp\u查询。我刚刚意识到您的查询参数是错误的。您设置了一个关系,但只有一个分类数组。另外,您不需要“=>数组(10)中的
'category\u”参数,它仅用于默认分类法“category”,您只需要自定义分类法“custcontegory”中的帖子,不是吗
您的查询应该是:
$r = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'custcategory',
'field' => 'term_id',
'terms' => array(10)
),
),
'post_type'=> $post_type ,
'posts_per_page' => $number,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
));
the_post()
方法在哪里?@rnevius更新了plz检查这到底是什么奇怪的行为?@ThemesCreator在分类页面中单独查看大多数帖子都不同,但在主页和详细信息页面中保持不变