0

I am getting array of post id from custom metabox.I tried

            $urls= get_post_meta( get_the_ID(), 'videos', false );
             foreach ( $urls as $url ) {
               foreach ( $url['link'] as $u ) { 
                 $posts[] = $u;
                     }
$my_query = new WP_Query( array( 'post_type' => 'slider', 'post__in' => $posts ) );

if ( $my_query->have_posts() ) {
   while ( $my_query->have_posts() ) {
        $my_query->the_post();
        the_title();
   }
}

wp_reset_postdata();
}

This loop query the selected post ids but they are not in id order.They are in default ASC order.Other approach that I have tried

$a=explode(" ",$u);
//$posts[]=$u;
$my_query = new WP_Query( array( 'post_type' => 'slider', 'post__in' => $a ) );

This shows only last post in the array.On var dump

string(2) "67" string(2) "77" //$u

1 Answer 1

0

Your first example also needs the orderby parameter set, otherwise it defaults to standard date order:

$my_query = new WP_Query(
    array(
        'post_type' => 'slider',
        'post__in' => $posts,
        'orderby' => 'post__in'
    )
);
1
  • Thx a lot.Saved my life Commented Jun 28, 2014 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.