goranseric
7/1/2014 - 6:21 PM

WP-3.4.php

<?php

$posts = array(5, 2, 43, 12);

// Get the posts
$my_loop = new WP_Query(array(
	'post__in' => $posts,
	'post_type' => 'any',
	'posts_per_page' => -1,
	'orderby' => 'post__in'
));

// Start the loop
if ($my_loop->have_posts()) : while ($my_loop->have_posts()) : $my_loop->the_post();
	the_title();
	the_content();
endwhile; endif;
<?php

$posts = array(5, 2, 43, 12);

// Get the posts
$my_loop = new WP_Query(array(
	'post__in' => $posts,
	'post_type' => 'any',
	'posts_per_page' => -1,
));

// Re order the posts
$reorder_loop = array();
foreach($posts as $rpid)
	foreach($my_loop->posts as $index => $fpid)
		if($fpid->ID === $rpid) $reorder_loop[] = $my_loop->posts[$index];
$my_loop->posts = $reorder_loop;

// Start the loop
if ($my_loop->have_posts()) : while ($my_loop->have_posts()) : $my_loop->the_post();
	the_title();
	the_content();
endwhile; endif;