Php 多个ID的Wordpress WP_查询返回null
我有以下数组:Php 多个ID的Wordpress WP_查询返回null,php,wordpress,Php,Wordpress,我有以下数组: array (12,15,21,32,33); 然后我使用以下查询来获取(以上ID的)帖子: $thew_query=newwp_query(数组(“post_uin”=>$ids_数组));//编辑 while($the\u query->have\u posts()) { $the_query->the_post();//在编辑时添加,但仍然不起作用 _title().“”; } 但我什么也得不到,没有错误,也没有中断。我已经检查了身份证,它们是正确的 编辑:我已将此查询
array (12,15,21,32,33);
然后我使用以下查询来获取(以上ID的)帖子:
$thew_query=newwp_query(数组(“post_uin”=>$ids_数组));//编辑
while($the\u query->have\u posts())
{
$the_query->the_post();//在编辑时添加,但仍然不起作用
_title().“
”;
}
但我什么也得不到,没有错误,也没有中断。我已经检查了身份证,它们是正确的
编辑:我已将此查询放在加载到页脚的模块末尾。我不知道它是否重要:你在($the_query->have_posts())时忘了添加
:$the_query->the_post()代码>
你只是检查你是否有帖子,但没有做进一步的工作
$ids_array = array (12,15,21,32,33);
$the_query = new WP_Query( array('post__in'=>$ids_array) );
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2></br>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
$ids_array=array(12,15,21,32,33);
$thew_query=newwp_query(数组('post_in'=>$ids_数组));
编辑
我认为这里的根本问题不是这个定制查询,因为这个定制查询是有效的。从您的评论中可以看出,您正在同一页面上使用另一个自定义查询
我不知道第一个查询的代码是什么样子的,但是这里有一些您需要去查看的疑难解答点
- 很可能您没有在第一次查询时重置postdata。这将中断您的第二个查询。在使用和运行自定义查询时,这一点非常重要。检查您在第一次执行
wp\u查询
后是否使用了wp\u reset\u postdata
。您的第一个查询的格式应与我的答案中的格式相同
- 您应该为
WP\u查询的每个实例使用不同的变量。例如,第一个实例为$variable1=new WP\u Query(您的参数)
,第二个实例为$variable2=new WP\u Query(您的参数)
如果$ids\u数组已经是一个数组,为什么要将其放入另一个数组中?您的代码不应该是$thew_query=newwp_query(数组(“post_uin”=>$ids_数组))代码>?它不工作。这可能是由于以前使用WP_查询造成的吗?因为当我使用带有“p”而不是“post_u_uin”的直接ID时,它仍然返回nothing?请参阅更新。根据您的评论添加了更多信息
$ids_array = array (12,15,21,32,33);
$the_query = new WP_Query( array('post__in'=>$ids_array) );
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2></br>
<?php
endwhile;
wp_reset_postdata();
endif;
?>