0

I used post__in key to get posts from the specific post ids and order order posts by the other array specific post ids.

I have following:

$post_ids=array(100,200,300,400,500,600,700,800,900,1000);
$orderby_post_ids = array(300,800,500); 
//$order=Ascending/ Descending;

If it Ascending order, expected output should be like this,

300,500,800,100,200,400,600,700,900,1000

If it Descending order, expecting output should be like this,

800,500,300,100,200,400,600,700,900,1000

How do I achieve above result using WP_Query? I used below arguments, but the result is not as expected.

$args = array(
        'post_type' => 'mycourses',
        'posts_per_page' => 4,
       'orderby' => 'post__in', 
       'order' => 'ASC',
       'post__in' => $post_ids,
    );
  • What are the results you are receiving? – Welcher Oct 4 '18 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.