Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks!

Added:

<?php 
/*
Template Name: Favorites page
*/

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

get_header();
get_sidebar(); 
?>


<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);
endwhile;

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

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

<?php 
get_template_part( 'rightsidebar' );
get_footer(); 
?>
share|improve this question
add comment

2 Answers 2

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
show 6 more comments

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
add comment

Your Answer

 
discard

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