views:

30

answers:

2

I'm trying to query posts based on a number of ID's that are contained in an array.

My array (called $my_array) looks like this:

Array
(
    [0] => 108
    [1] => 129
    [2] => 145
)

And my Query looks like this:

<?php query_posts(array('post__in' => $my_array)); ?>

However this just returns one post, the post has the ID of the first item in the array (108).

Do I have my syntax wrong?

A: 
$args = array(
  'post_type' => 'page',//or whatever type
  'post__in' => array(108,129,145)
  );
query_posts($args);

or

$arr=array(108,129,145);
$args = array(
  'post_type' => 'page',
  'post__in' => $arr
  );
query_posts($args);
stormdrain
A: 

You always have to set the post_type with the post__in argument. So your line should look like the following:

<?php query_posts(array('post_type' => 'post', 'post__in' => $my_array)); ?>

That will query the posts with the IDs you have in the array.

Kau-Boy