Created
July 21, 2013 19:10
-
-
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.
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
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