Wordpress Logo

How to Display Custom Post Types in WordPress?

How to Display Custom Post Types in WordPress?

Wordpress Logo

In my food blog, I recently added a new custom post type called “recipe” to showcase a new section that focuses more on home cooking. Although I could have easily created a new category for it, I used a custom post type in order to organize it better and give it its own section in my admin dashboard.

Creating a new post type was easy thanks to the GD CPT Tools plug-in however, displaying it on the blog was a different matter. At first, it doesn’t show up at all and you can only view it via its direct link. It doesn’t show up in the homepage, archives, categories, tags nor search. This meant that it wasn’t visible at all if you don’t know the exact url.

I did a few google searches to find out what was wrong and how to display the posts from the custom post types in wordpress. I stumbled upon this solution that solved the problem easily.

In your Admin Dashboard, go to Appearance -> Editor. We will need to edit the functions.php file

Paste this code at the bottom.

function add_custom_types_to_tax( $query ) {
if( is_category() || is_home() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {

// Get all your post types
//$post_types = get_post_types();
$post_types = array( 'post', 'recipe' );

$query->set( 'post_type', $post_types );
return $query;
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );

Save and that’s it!

Some notes that you might find useful:

  • I commented out “get_post_types” so that I can specify the post types I’d like to include in the array.¬†In my case, I want to show “post_type” as this is the default for posts and my recipe¬†posts which is a custom post type.
  • The if command up there shows that this custom post type will show up in category, home and tag pages. I’m thinking that if we delete the if, it will show up everywhere ? (but I still need to test that theory)

Till next time,



  • http://www.wprecipes.com/how-to-display-custom-post-types-on-your-wordpress-blog-homepage
  • http://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/
  • http://codex.wordpress.org/Post_Types

One thought on “How to Display Custom Post Types in WordPress?

Leave a Reply