Created
September 14, 2015 00:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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