Displaying custom post types on your WordPress blog homepage

So you have created a great new custom post type in WordPress 3.0 but it doesn’t show on your homepage. To add your new post type to the homepage you could use the following code in your functions.php. As you can see this code sets all the post types you would like to have displayed by using the pre_get_posts filter. I think using the filter would be great but currently it breaks the new menu’s in WordPress 3.0.

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {
	if ( is_home() )
		$query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) );

	return $query;
}

So to add your custom post types into the your blog homepage you can put this code just before the WordPress post loop. The following code adds in the post types you would like to use and also checks to make sure your paging still works.

array( 'post', 'linkpost'),'paged'=>$paged ) );
}
?>

if you want to read more about the first piece of code you can check it out on Justin Tadlock’s blog.

2 thoughts on “Displaying custom post types on your WordPress blog homepage”

Comments are closed.