WordPress Custom Post Types Add Custom Post Types to Main Query


Registering a custom post type does not mean it gets added to the main query automatically. You need to use pre_get_posts filter to add custom post types to main query.

// Show posts of 'post' and 'book' custom post types on home page
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
  if ( is_home() && $query->is_main_query() )
    $query->set( 'post_type', array( 'post', 'book' ) );
  return $query;