WordPress : Custom order for custom post types on WP_Query

I’m calling two different post types in WordPress:

$args = array( 'post_type' => array('post','testimonial'), 'posts_per_page' => 6 ,
                   'meta_key'   => 'show_on_home',
    'meta_value' => true
                 );
$loop = new WP_Query( $args );

I want to know if there is any way to export result like this order

Read More

“post-testimonial-post-testimonial-post-testimonial”

since they are different post types I can’t use normal ASC or DESC orders.

Is there any other way?

Related posts

1 comment

  1. Well, I used this method to solve problem.
    Wants to share if anyone need it later:

    $args = array('post_type' => array('post', 'testimonial'), 'posts_per_page' => 6,
                   'meta_key' => 'show_on_home',
                   'meta_value' => true,
                   'orderby' => 'type',
                   'exclude'=>1
                  );
                  $loop = new WP_Query($args);
    
                  $posts = $loop->get_posts();
    
    $a = $posts;
    $b = array(3, 0, 4, 1,5,2); // rule indicating new key order
    $c = array();
    foreach($b as $index) {
        $c[$index] = $a[$index];
    }
    $posts=$c;
    

Comments are closed.