Skip to content

Instantly share code, notes, and snippets.

@unknowndomain
Created July 21, 2013 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unknowndomain/6049593 to your computer and use it in GitHub Desktop.
Save unknowndomain/6049593 to your computer and use it in GitHub Desktop.
This code will ensure that all WordPress custom post types appear in the main blog loop/query on the home page as if they were normal posts.
function pre_get_posts( $query ) {
if ( $query->is_main_query() && ! $query->is_admin && $query->is_home ) {
$post_types = get_post_types( array(
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'hierarchical' => false
) );
if ( isset( $post_types['attachment'] ) )
unset( $post_types['attachment'] );
$query->set( 'post_type', $post_types );
}
}
add_action( 'pre_get_posts', 'pre_get_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment