Skip to content

Instantly share code, notes, and snippets.

@zachary-russell
Created December 7, 2013 18:44
Show Gist options
  • Save zachary-russell/7846892 to your computer and use it in GitHub Desktop.
Save zachary-russell/7846892 to your computer and use it in GitHub Desktop.
Show CPT on Home Page
<?php
/**
* Show WordPress custom post types on the main blog and archive pages
*
* @param WP_Query $query
**/
function show_custom_post_types( $query ) {
// Show all custom post types on main blog and archive pages
if ( $query->is_main_query() && ( is_home() || ( is_archive() && !is_post_type_archive() ) ) ) {
$custom_post_types = get_post_types( array(
'public' => true,
'_builtin' => false,
) );
$post_types = array_merge( array('post'), $custom_post_types );
$query->set( 'post_type', $post_types );
}
return $query;
}
add_filter( 'pre_get_posts', 'show_custom_post_types' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment