-
-
Save goranseric/0276e1659f8864b532d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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