Wordpress theme options page query_posts
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();
?>
When I echo var_dump = string(11) "32,39,43,45"
In which case, you need to explode $vehicle1
, since post__in
expects an array;
query_posts(array(
'post_type' => 'page',
'post__in' => @explode(',', $vehicle1)
));
Update
When I just replace array(32,39,43,45) with array($euro_box_1_vehicles) it only returns one result.
Shouldn't you replace array(32,39,43,45)
with $euro_box_1_vehicles
not array($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.
<?php
$vehicle1 = array(
'post__in' => array(32,39,43,45),
'post_type' => 'page',
);
query_posts( $vehicle1['post_in'] ); //use sub-array that contains list
while (have_posts()) : the_post();
?>
精彩评论