Snippets: Add Custom Post Types To Your “Posts Page” (Blog)

If you have added custom post types to your site and want them to display in your main "Posts Page" as defined under Settings > Reading you can do this easily with the code below. Simply change 'YOUR_CPT' with your custom post type name and add as many you want to include to the array.

function myprefix_add_cpts_to_blog( $query ) {
	if ( ! is_admin()
		&& $query->is_main_query()
		&& $query->is_home()
	) {
		$query->set( 'post_type', array( 'post', 'YOUR_CPT' ) );
add_action( 'pre_get_posts', 'myprefix_add_cpts_to_blog' );

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.