Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Created September 14, 2015 00:51
Show Gist options
  • Save chuckreynolds/2c6ef0ace41b6318db26 to your computer and use it in GitHub Desktop.
Save chuckreynolds/2c6ef0ace41b6318db26 to your computer and use it in GitHub Desktop.
Add another custom post type into the main blog post archive loop. #WordPress
/**
* Add a CPT into main post/blog archive
*/
add_filter( 'pre_get_posts', 'chuckreynolds_add_cpts_to_post_archive' );
function chuckreynolds_add_cpts_to_post_archive( $query ) {
if ( is_home() && $query->is_main_query() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', // assuming you still want normal posts in there
'cpt-name' // registered custom post type name
));
return $query;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment