Make Custom Post Behave Like Normal Post?

Is there a way to force Custom Post Types to behave as normal wp posts?

Hi – I need some help adding a custom post type to my theme’s posts section. The posts page is a static page using a template (not the standard wp home/blog page). The template allows me to select post categories to feature on the page, but my custom post types never show up in the choices.

If I select “show all posts” the custom posts still don’t show up on the published page unless I add the following code to the end of my functions.php

My custom posts then show up in among the regular posts (as I wanted) BUT, it messes up the layout of the site (the main nav menu disappears!)

add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
    $query->set( 'post_type', array( 'post', 'page', 'projects' ) );
return $query;
}

Solutions Collecting From Web of "Make Custom Post Behave Like Normal Post?"

The reason its messing up is because its adding the custom post type everywhere. You want to limit it to just the main loop of the main page. Justin Tadlock wrote an article on how to do that here. Here is what your code should look like:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {    
    if ( is_home() && $query->is_main_query() )
         $query->set( 'post_type', array( 'post', 'page', 'projects' ) );    
    return $query;
}

This limits it to just the main loop of the home page.