Skip to content

Snippet: 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' );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top