Skip to content

Instantly share code, notes, and snippets.

@goranseric
Forked from nmec/WP-3.4.php
Created July 1, 2014 18:21
Show Gist options
  • Save goranseric/0276e1659f8864b532d4 to your computer and use it in GitHub Desktop.
Save goranseric/0276e1659f8864b532d4 to your computer and use it in GitHub Desktop.
<?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;
<?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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment