I’m going to take the answer you posted for yourself and suggest a couple of improvements.
Some things I’ll address:
- The 3rd query is unnecessary. There are simpler ways to sort by date. Just make both queries for the full post content and merge the results.
- Since we’re not going to be using
have_posts()
andthe_post()
(we’ll usesetup_postdata()
), we should just useget_posts()
to keep things a bit simpler. It should also be a bit quicker as it sets some default query args to optimise it since it won’t need pagination info. - We’ll avoid repeating ourselves with the query arguments by re-using a single array of arguments.
- We won’t bother specifying arguments that are just the defaults.
Taking those points into account, the code can just be:
$posts_args = [
'posts_per_page' => $postsnumber,
'post_type' => 'post',
];
$posts = get_posts( $posts_args );
$video_args = $posts_args;
$video_args['post_type'] = 'js_videos';
$video_args['tax_query'] = [
[
'taxonomy' => 'video_category',
'field' => 'tag_ID',
'terms' => '41',
],
];
$videos = get_posts( $video_args );
$combined = array_merge( $posts, $videos );
usort(
$combined,
function( $a, $b ) {
return get_post_time( 'U', false, $b ) - get_post_time( 'U', false, $a );
}
);
global $post;
foreach ( $combined as $post ) : setup_postdata( $post );
the_title(); // etc.
endforeach;
wp_reset_postdata();