How to show posts from multiple post types in a single loop? And display them separately on the same template

I have four post types

  1. Products
  2. Banners
  3. Portfolio
  4. Testimonials

And they all display their posts on the same home page template (index.php).

Currently using below query to get posts from different post types.

<?php
query_posts(
    array(
        'post_type' => 'work_projects',
        'work_type' => 'website_development',
        'posts_per_page' => 100
    )
);
if ( have_posts() ) : while ( have_posts() ) : the_post();

    the_post_thumbnail($size);
    the_title();
    the_content();

endwhile; endif;

But my problem is I have to put multiple query_post loops on the same page. I googled some solutions and found answers as well here on Stack Overflow also. But not able to figure it out how to use them with the_title(), the_content() and the_post_thumbnail().

Solutions Collecting From Web of "How to show posts from multiple post types in a single loop? And display them separately on the same template"

Best practice would be to use four different custom queries and loop through each one separately using wp_query

So here’s an example:

<?php
$custom_query = new WP_Query( 
    array(
        'post_type' => 'work_projects', 
        'work_type' => 'website_development', 
        'posts_per_page' => 100
    ) 
);
if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post();

    the_post_thumbnail($size);
    the_title();
    the_content();

endwhile; endif; wp_reset_query();
?>

And then you would repeat the process for each post type, replacing ‘work_projects’ with the name of the next post type.

I’m not sure what ‘work_type’ is in this scenario, but I just put it back into the query since you already had it there.

post_type accepts an array.
Have you tried using WP_Query with an array?

'post_type' => array( 'product', 'banner', 'portfolio, 'testimonial' )