How to WP_Query() from multiple blogs and order them?

Question

Dear WordPress community,

my job seems quiet hard now. We have a blog for articles and another for videos and I now have to produce a list of it, ordered. Paginatedly. This is what I tried:

switch_to_blog(1);
$query = (new WP_Query([
    'post_type' => 'video',
    'post_status' => 'publish',
    'posts_per_page' => 30,
    'paged' => 1,
    's' => 's',
    'orderby' => 'date',
    'order' => 'DESC'
]))->posts;

and:

switch_to_blog(2);
$query = (new WP_Query([
    'post_type' => 'article',
    'post_status' => 'publish',
    'posts_per_page' => 30,
    'paged' => 1,
    's' => 's',
    'orderby' => 'date',
    'order' => 'DESC'
]))->posts;

the problem is, the output is not correct of course. Both the resultset can only be appended not merged. The best would be:

switch_to_blog([1,2]);
$query = (new WP_Query([
    'post_type' => 'article',
    'post_status' => 'publish',
    'posts_per_page' => 30,
    'paged' => 1,
    's' => 's',
    'orderby' => 'date',
    'order' => 'DESC'
]))->posts;

but as of my knowledge, its not possible. Then how?

0
user195354 4 months 0 Answers 12 views 0

Leave an answer