永远不要重新执行主查询。钩入pre_get_posts
然后改变它。在您的functions.php
(输入模板将意味着运行太晚):
add_action( \'pre_get_posts\', function ( $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->is_tag() ) {
$wp_query->set( \'posts_per_page\', 20 );
$wp_query->set( \'post_type\', [
\'pavilion\',
\'post\',
\'catalog\',
\'tenders\',
\'services\',
]);
}
});
现在,您的模板代码应该是:
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// your code!
}
}