我试图从循环中排除一个帖子,比如:
query_posts("posts_per_page=5&cat=1, -15&post__not_in = 1");
但是,post__not_in
不起作用。我的命令全错了吗?
它不起作用的原因是post__not_in
需要一个数组,当您使用WP_Query类时可以使用该数组。
尝试改用WP_Query
:
$args = array('posts_per_page' => 5,
'cat' => '1,-15',
'post__not_in' => array(1),
);
$posts = new WP_Query( $args );
while ($posts->have_posts()) {
$posts->the_post();
echo the_title() . '<br />';
}