WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a variable containing some post ID´s. I´d like to output the posts in that variable using the standard wordpress loop. How can I do that?



Template Name: Favorites page

$favorites = wpfp_get_users_favorites($user = '');
$favorites_query = new WP_Query('post__in' => $favorites);


<div id="maincolumn" class="alignleft">
<?php get_template_part( 'menu' );

if(!$favorites) {
echo '<div class="box content alignleft">'; echo _e('Du har ingen favoritter', 'deals'); 
echo '</div>';

if($favorites) {
echo '<div class="box content alignleft">'; echo _e('Dette er dine favoritttilbud denne  uka. Favorittene dine vil kún være være tilgjengelig i denne nettleseren på denne maskinen.', 'deals'); 
echo '</div>';

while ($favorites_query->have_posts()) : $favorites_query->the_post(); 
$start = get_post_meta($post->ID, '5Start', true);
$stop = get_post_meta($post->ID, '6Slutt', true);

 echo print_offer($post_id, $start, $stop);

if($favorites) {
echo '<div class="box content alignleft">';
echo '</div>';
} ?>

</div> <!-- End maincolumn -->

get_template_part( 'rightsidebar' );
share|improve this question
up vote 2 down vote accepted

An example:

$posts_ids = array(2,56,87,23,5); // this is an array of posts IDs

<?php $my_query = new WP_Query(array('post__in'=>$posts_ids)); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <!-- Do stuff... -->
<?php endwhile; ?>
share|improve this answer
My page turns totally blank when using this code. Could there be a syntax error in there? – Espen Arnoy Oct 4 '10 at 23:26
I´ve added this code and it causes the whole page to go blank: $favorites = wpfp_get_users_favorites($user = ""); $favorites_query = new WP_Query('post__in' => $favorites); – Espen Arnoy Oct 4 '10 at 23:37
Look at your error log for the error message or add "define( 'WP_DEBUG', true );" at the top of your config file – sorich87 Oct 5 '10 at 6:28
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /Users/Espen/Sites/local/wordpress/wp-content/themes/Hverdagskupp/favorites_page‌​.php on line 7 – Espen Arnoy Oct 5 '10 at 7:59
write wpfp_get_users_favorites(); instead of wpfp_get_users_favorites($user = ""); – sorich87 Oct 5 '10 at 8:12

I think You should set $user Name

wpfp_get_users_favorites($user = "")
share|improve this answer
Please explain why that would solve the problem. – toscho Feb 23 '13 at 20:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.