• Hi

    Im trying to use the query_posts() and send in an array of id:s. The problem is that I cant get out post in the same order I send them in, is that possible. There seem to bee no order option for this and the id:s seems to get some defaukt ordering?

    $args = array(
    ‘posts_per_page’ => 3,
    ‘post__in’ => array(1,32,2),
    ‘orderby’ => ‘none’
    );

    query_posts($args);

    I want my posts displayed in the sam order I send in the post_Id:s

    regards // Johannes

Viewing 3 replies - 1 through 3 (of 3 total)
  • Probably going to need to do something like:

    <?php
    $post_ids = array(1,32,2);
    foreach( $post_ids as $id ) {
     $args = array(
       'post__in' => array($id)
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        endwhile;
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter johannesfosseus

    (@johannesfosseus)

    ok, thanks.

    Do you have any thoughts of witch one nicer to the database?

    this one….

    foreach( $post_ids as $id ) {
    $args = array(
    ‘post__in’ => array($id)
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php the_title(); ?></p>
    <?php
    endwhile;
    }
    }

    of something like this?

    foreach( $post_ids as $post_id ) {
    $post = get_post($post_id);
    echo $post->post_title;
    }

    many thanks for the reply // JOhannes

    Probably about the same.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘query_posts() ordering’ is closed to new replies.