Forums

How do I sort posts by post__in ? (4 posts)

  1. odyodyodys
    Member
    Posted 9 months ago #

    I want to retrieve a custom set of pages and sort them manually (in the post__in order)

    my code is:

    query_posts(array(
    'post__in'=>array('16','20','22'),
    'post_type'=>'page',
    'order' => 'post__in'
    ));
    
    if ( have_posts() ) while ( have_posts() ) : the_post();
    	the_title();
     endwhile;

    But the output is the titles ordered by date.
    I am using the 'order' => 'post__in' as used in this article.

  2. alchymyth
    The Sweeper
    Posted 9 months ago #

    as far as i can read, that article uses:

    'orderby' => 'post__in'

    it also assumes that you have activated that plugin.

  3. odyodyodys
    Member
    Posted 9 months ago #

    Thanks alchymyth, I am using the plugin at the moment. My question was more about the wordpress core. If I can have that result without using a third party plugin.
    I want just to display posts in a specified order.
    I could do multiple loops using WPquery but this is a funny solution :)

  4. Big Bagel
    Member
    Posted 9 months ago #

    This page has all the available options you can pass into 'orderby' without using any plugin. Perhaps one of them is what you're looking for?

Reply

You must log in to post.

About this Topic