using a dynamic array with query_posts and post__in
-
I’m trying to use query_posts and post__in to display posts from a dynamically generated array. I’ve got the array working great and can echo it anywhere on the page that I want. (it echoes via implode as: 543, 234, 433 etc. which are the desired post IDs). When I try to throw the array in a variable and use that variable within post__in it doesn’t work as expected. Here’s what I’m using…
$horse_array = implode(', ', $horse_var); echo $horse_array; // this echoes: 546, 540, 550 <?php query_posts( array( 'post_type' => 'client_horses', 'orderby' => 'title', 'order' => 'asc', 'horse-status' => 'mare', 'post__in' => array($horse_array) ) ); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> MY LOOP STUFF... (only displays the last post in the array) <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?>
So this will show me the last item in the array but ONLY the last item. I would expect it to just show all the items within the array but nope. I know that the array has more than one item in it since it echoes multiple items just before (and after) my query. I also tried imploding the array within the post__in param but that didn’t work either.
Thoughts anyone?
- The topic ‘using a dynamic array with query_posts and post__in’ is closed to new replies.