我有以下代码:
$recommended_args =
array(
\'post_type\' => \'post\',
\'posts_per_page\' => 3,
\'post__in\' => get_option(\'sticky_posts\'),
\'orderby\' => \'date\'
);
$recommended_query = new WP_Query($recommended_args);
if ($recommended_query->have_posts()) {
while($recommended_query->have_posts()) {
$recommended_query->the_post();
get_template_part("templates/article-random");
}
}
基本上,它应该返回标记为粘滞的最近3篇帖子。但是,它会将DB中的所有(超过3个)粘性帖子转储到屏幕上。这些论点有什么问题?有没有一种方法可以修复此问题而不必更换while
循环使用for
循环,仅在WP_Query
对象