WordPress 主题选项页面 query_posts
我正忙于为一位客户构建一个小型主题选项页面,并且需要一些帮助来解决问题。
目前,我可以选择手动放入 WordPress 页面的 IDS,
以根据主题选项使用 query_posts
提取数据,创建一个名为 $euro_box_1_vehicles;
的变量,
我的选项已填充输入中的 as 32,39,43,54
,当我用 echo 打印此语句时,得到相同的结果。
当我用 array($euro_box_1_vehicles)
替换 array(32,39,43,45)
时,它只返回一个结果。
<?php
$vehicle1 = array(
'post__in' => array(32,39,43,45),
'post_type' => 'page',
);
query_posts( $vehicle1 );
while (have_posts()) : the_post();
?>
I am busy building a small theme options page for one of clients and need some help with an issue.
currently i have the option to manually put in IDS of wordpress pages to extract the data with query_posts
based on the theme options is creates a variable called $euro_box_1_vehicles;
my options are filled in as 32,39,43,54
in the input, and when I print this statement with echo, I get the same result.
When I just replace array(32,39,43,45)
with array($euro_box_1_vehicles)
it only returns one result.
<?php
$vehicle1 = array(
'post__in' => array(32,39,43,45),
'post_type' => 'page',
);
query_posts( $vehicle1 );
while (have_posts()) : the_post();
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,您需要 爆炸
$vehicle1
,因为post__in
需要一个数组;In which case, you need to explode
$vehicle1
, sincepost__in
expects an array;更新
难道您不应该将
array(32,39,43,45)
替换为$euro_box_1_vehicles
不array($euro_box_1_vehicles
>)?后者似乎会创建一个带有一个参数的嵌套数组,即 array(array(32,39,43,45))。这不是你想要的。老答案...
如果我没看错的话,那么 query_posts() 需要一个 ID 列表? (32,39,43,45)
但是当你传递 $vehicle1 时,你并没有给它一个 ID 列表,而是一个二维数组。
Update
Shouldn't you replace
array(32,39,43,45)
with$euro_box_1_vehicles
notarray($euro_box_1_vehicles
)? The latter seems it would make a nested array with one argument, i.e. array(array(32,39,43,45)). Which is not what you want.Old Answer....
If I read you right then query_posts() expects a list of IDs? (32,39,43,45)
But when you pass it $vehicle1 you are not giving it a list of IDs, but a 2-dimensional array.