Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Multiple Post Type Query by category

Multiple Post Type Query by category

// WP_Query arguments
$args = array (
	'post_type'              => array( 'post-1', ' post-2', ' post-3' ),
	'post_status'            => array( 'published' ),
	'category_name'          => 'main-post',
	'orderby'                => 'title',
);

// The Query
$args = new WP_Query( $args );

// The Loop
if ( $args->have_posts() ) {
	while ( $args->have_posts() ) {
		$args->the_post();
		// do something
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();