第一点是,您不应该使用query_posts()
用于自定义查询。更好的方法是使用WP_Query
班更多信息请访问WP docs 和here.
此示例将显示您的2篇特色文章,然后在第二次查询中排除它们。
// We will push the ID of your featured posts to this array
$excl_posts[] = \'\';
// Query arguments from your featured posts query
$feat_args = array(
\'posts_per_page\' => \'2\',
\'meta_query\' => array(
array(
\'key\' => \'featured_post\',
\'value\' => \'1\',
\'compare\' => \'LIKE\'
)
)
);
// Instantiate new WP_Query instead of using query_posts()
$featured = new WP_Query( $feat_args );
if ( $featured->have_posts() ):
while ( $featured->have_posts() ):
$featured->the_post();
// Do stuff with each posts
echo get_the_title() . "<br>";
// Push current postID onto the exclude array
$excl_posts[] = get_the_ID();
endwhile;
endif;
wp_reset_postdata();
$excl_feat_args = array(
\'posts_per_page\' => \'10\',
\'post__not_in\' => $excl_posts,
\'meta_query\' => array(
array(
\'key\' => \'featured_post\',
\'value\' => \'1\',
\'compare\' => \'LIKE\'
)
)
);
$excl_featured = new WP_Query( $excl_feat_args );
if ( $excl_featured->have_posts() ):
while ( $excl_featured->have_posts() ):
$excl_featured->the_post();
echo get_the_title() . "<br>";
endwhile;
endif;
wp_reset_postdata();