I have a multisite Installation and have merged get_posts() queries to get it ordered by date. The Problem is now, to get the thumbnail of each post because the $post has no ‘blog_id’ Information.

Is there a way to search by guid over the whole database? Or could i extend the queries with the blog id or thumbnail that i can use it in the foreach?

Here is the function to get the Posts:

function get_multisite_posts( $args = 'posts_per_page=5') {


    $custom_posts = array();
    $blog_ids = wp_get_sites();
    foreach ($blog_ids as $key=>$current_blog) {
        switch_to_blog($current_blog['blog_id']);
        $custom_posts = array_merge($custom_posts, get_posts($args));
        restore_current_blog();
    }

    $custom_posts = wp_list_sort( 
        $custom_posts, 
        'post_date_gmt',
        'DESC'      
    );

        return $custom_posts;
}

And here then I do the foreach:

foreach($custom_posts as $post) : setup_postdata($post);

If the post is from the current blogID, then I get the thumbnails. If the post is from another blogID, I get – of Course – nothing.

Anyone has an idea?

Thank you very much in advance.

Read more here: Multisite – get thumbnail for merged get_posts() queries


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: