how to retrieve WP_Query without ordering by date

I want to use

$ps = "9126,8955,8554,8620,8825,8912,8937,8813,9054,9022";
$recent = new WP_Query( array('post__in' => explode(',', $ps)) );

to retrieve posts by ID, I do and the result ordered by publish date but I want to retrieve in same of IDs in this example in this order:

9126,8955,8554,8620,8825,8912,8937,8813,9054,9022

Related posts

Leave a Reply

2 comments

  1. Personally, if the order of posts as well as your ID numbers are going to be that strict, I would probably avoid using WP_Query:

    <?php
    $ids = array(9126,8955,8554,8620,8825,8912,8937,8813,9054,9022);
    foreach($ids as $id)
    {
        $post = get_post($id);
        setup_postdata($post);
        ?>
        <!-- YOUR HTML HERE -->
        <?php
    }
    ?>
    

    Otherwise, since Posts do not have any kind of Menu Order option like Pages do, you will probably have to set a Custom Field and give it a value (with lower numbers taking priority over higher numbers). Then you can do something like this:

    <?php
    $ids = array(9126,8955,8554,8620,8825,8912,8937,8813,9054,9022);
    $recent = new WP_Query(array('post__in' => $ids, 'orderby' => 'meta_value_num', 'meta_key' => 'postOrder', 'order' => 'ASC'));
    ?>
    

    This second option is untested and I can’t guarantee it will work right off the bat, but it should get you started. Good luck.