从wp_查询循环wordpress中排除帖子
我用以下代码在页面中显示我的最后一篇文章:从wp_查询循环wordpress中排除帖子,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我用以下代码在页面中显示我的最后一篇文章: $query1 = new WP_Query(); $query1->the_post(); 并进一步指出: $id = $query->ID; 检索最后一个帖子ID 因此,我编写了一个新的wp_查询,并希望从结果中排除该ID: 我写了这篇文章,但它不起作用: $query2-> new WP_Query('p=-$id'); 有什么问题吗?您没有排除任何内容p=包括帖子。这并不排除他们。您需要的是post\u而不是\u in
$query1 = new WP_Query();
$query1->the_post();
并进一步指出:
$id = $query->ID;
检索最后一个帖子ID
因此,我编写了一个新的wp_查询,并希望从结果中排除该ID:
我写了这篇文章,但它不起作用:
$query2-> new WP_Query('p=-$id');
有什么问题吗?您没有排除任何内容<代码>p=包括帖子。这并不排除他们。您需要的是
post\u而不是\u in
$query2-> new WP_Query(array('post__not_in' = array($id)));
我的代码工作正常:
$ID =array('1,2,3,4,5');
$news = new WP_Query(array('
'post_type' => 'post',
'showposts' =>3,
'order' => 'DESC',
'post__not_in' => $ID
));
if ( $news->have_posts() ) :
echo '<div>';
while ( $news->have_posts() ) : $news->the_post(); ?>`
//Your code here
$ID=array('1,2,3,4,5');
$news=新的WP\u查询(数组('
“post_type”=>“post”,
“展示柱”=>3,
“订单”=>“描述”,
'post\u not\u in'=>$ID
));
如果($news->have_posts()):
回声';
而($news->have_posts()):$news->the_post();?>`
//你的代码在这里