How to display custom post types on your WordPress blog homepage

How to display custom post types on your WordPress blog homepage

The following code have to be pasted in your functions.php file. Once the file will be saved, it will work.
As you can see in the code, the post, page, album, movie, quote, and attachment types will be displayed. Modify that line to fit your own needs.

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;
}

Please note that custom post types are not available by default on WordPress 2.9. You could have a look there if you’re looking to implement that functionnality right now.

Credits goes to Justin Tadlock for this handy recipe!

By the way, if you’re looking to advertise on WpRecipes, I got a free spot so be quick! Click here to buy.

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to display custom post types on your WordPress blog homepage

Leave a Reply

Your email address will not be published. Required fields are marked *