First off, query_posts
is terrible doesn’t use it. It does all kinds of fun things like mess up the very useful conditional tags like is_singular
and the like as well as mess up pagination.
Short of hooking into the posts_orderby
filter and writing some custom order by SQL, your best bet is to use the post__in
argument combined with the post__in
orderby argument that was added in WP 3.5.
Example:
<?php
$custom_query = new WP_Query(array(
'post__in' => array(1, 2, 4, 5, /* whatever your post ID's are here */),
'orderby' => 'post__in',
));
while ($custom_query->have_posts()) {
$custom_query->the_post();
// use the normal template tags here
?>
<a href="https://wordpress.stackexchange.com/questions/89148/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php
}
// restore the original query
wp_reset_query();