是的,是的。首先,必须将结果合并到一个数组中:
$all_posts = array_merge( $related->posts, $features->posts );
现在,让我们按日期对数组项进行排序:
usort( $all_posts, function( $a, $b ) {
return strcmp( $b->post_date, $a->post_date );
} );
最后,执行循环:
global $post;
foreach ( $all_posts as $post ) {
setup_postdata( $post );
// use the template tags here: the_title(), the_content(),…
}
wp_reset_postdata();