Reputation: 563
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
"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?
Upvotes: 1
Views: 2368
Reputation: 563
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;
Upvotes: 2