197 Responses

  1. Cristian Antohe
    Cristian Antohe Published |

    One thing I don’t really understand is how/where I select what post type I’m about to write in the backend. Particularly when we don’t have a UI for that yet.

    1. Matt Wiebe
      Matt Wiebe Published |

      I believe that the UI stuff is what’s coming in 3.0.

    2. Patrick Daly
      Patrick Daly Published |

      If you’re using the trunk version you can see the UI, but you have to register your post type first.

      function post_type_movies() {
      	register_post_type('movies', array('label' => __('Movies'), 'public' => true ) );
      	register_taxonomy_for_object_type('post_tag', 'movies');
      add_action('init', 'post_type_movies');

      Just replace “movies” with whatever you want.

      1. Cristian Antohe
        Cristian Antohe Published |

        Ok. This makes sense. So there is no real way of using custom post types with 2.9.1 🙂

      2. Dustin Dempsey
        Dustin Dempsey Published |

        Nice, can’t wait for your full tutorial when 3.0 is released.

        I feel these will evolve into complete custom write panels, image the possibilities.

      3. Jason Pelker
        Jason Pelker Published |

        It’s difficult to be patient for all the features coming in 3.0! It’ll likely be the most revolutionary WordPress version yet and in all truth, it will subsequently become the defacto CMS throughout the world.

      4. Elio
        Elio Published |

        As Justin says, in addition to the code you still have to do the UI panel. Right now WP 3.0 trunk doesn’t display any UI even after registering post types.

      5. David Tufts
        David Tufts Published |

        I got this to work in the current trunk including the UI panel with a couple of simple additions to you code.

        function post_type_movies()
        register_post_type('movies', array('label'=>__('Movies'), 'public'=>true, 'show_ui'=>true, 'exclude_from_search'=>false));
        register_taxonomy_for_object_type('post_tag', 'movies');

        add_action('init', 'post_type_movies');

  2. Abu Aufa's Weblog
    Abu Aufa's Weblog Published |

    Wow.. great features, Can’t wait for WP 3.0

  3. Michael Fields
    Michael Fields Published |

    Great example! I’ve never used $query->set() before. I believe that you just opened up a whole new world for me. Thanks!

  4. Peter
    Peter Published |

    Very useful information. Especially for a newbie like me. I will try to implement that on my blog. Thanks.

  5. Andrew
    Andrew Published |

    Wordpress 3.0 is coming? I don’t think I’ll upgrade that quickly when it comes out, maybe I’ll have to wait it out till 3.1 comes out.

  6. Nathan Rodriguez
    Nathan Rodriguez Published |

    Cool feature, but i think is better wait for the 3.0 version of WP, im not confident enough on messing on installation files.

  7. Rinaldi Syahran
    Rinaldi Syahran Published |

    Hi, another use from this wordpress 3.0 . Very thankful to you for sharing.

  8. Bhandari Group
    Bhandari Group Published |

    I will try this one as soon as i get WP 3.0. A great stuff to help the bloggers. Really i need the code for that and you have provided it.

  9. Karen Mae Farro
    Karen Mae Farro Published |

    I can’t wait for Wordpress 3.0! I’ll be waiting for your tutorial.

  10. First Impressions of Custom Post Type - label, public, excludefromsearch, publiclyqueryable, showui, inherittype - WP Engineer
  11. shawn
    shawn Published |

    Am I correct to assume that 3.0 will introduce new admin panels for custom post_types?

    So in 3.0 if I create a custom post type ‘movies’ I will then have a new ‘movies’ choice in the admin panel where the user could input the information relevant to ‘movies’ only?

    Right now with 2.9 I basically create new meta field boxes for the admin to fill in while writing a post. The problem comes into effect when I have ‘movies’ as a type of post, and say ‘music’ as a second type.

    Right now in 2.9 both the meta input boxes show up in the ‘add article’ admin section, which makes it really confusing to the user. They have the ability to input information both for movies and music on the same ‘add article’ admin page.

    This would indeed go a long ways into turning wp into more of a cms, where the author has a much clearer path as to where to input the data for each type of post…. boy I sure hope I am right.

  12. Jason Pelker
    Jason Pelker Published |

    How do custom posts jive with traditional taxonomies, such as categories and tags? If I queried a category, would all posts and (musics, et al) that have that category display?

    1. Matthew Simo
      Matthew Simo Published |

      I’m interested in this, I heard that they were adding the Categories and Tags taxonomies to Pages so, at least in my mind, it makes sense that they would apply to both. And I’m assuming that custom-post types would also be applicable, as long as you made sure they were registered for those taxonomies.

      Which, if that is true then it makes sense that any custom taxonomies could also be registered across multiple custom post-types, as well as your posts and pages, if you desired as well..

      Very exciting stuff.

  13. palPalani
    palPalani Published |

    nice feature, this is very useful for me.

  14. L’Hebdo WordPress : WordPress 2.9 – WordPress 3.0 – BuddyPress
  15. WordPress Picks for the Week [02/17] | Techtites
  16. How to display custom post types on your WordPress blog homepage
  17. Elad
    Elad Published |


    As you wrote, if I remove the ‘attachment’ type I’ll get the posts without the images. I would like to get the images without the posts but when I omit the ‘post’ type’, and leave onle the ‘attachment’ type, I get nothing.

    Any idea?

  18. Robert
    Robert Published |

    I’ve just been playing around with this in WP 3.0 svn and so far so good. I can easily create a new post type, assign the default post features and custom taxonomies and get it all in a custom write panel. It’s also easy to create custom meta boxes linked to the new post type.

    What I’m wondering about is:

    1. How will adding custom fields to the custom post type be managed (one could just use the post custom fields but what if it’s a more complex post type that warrants its own DB table.)
    2. I’d like to see an interface to also be able to add arbitrary custom fields to the Quick Edit part on the post list.

    I guess what I want to be able to do is create custom front end functionality depending on the post type. For example:

    Event Post Type
    – display additional fields like event date, duration, venue, contact, etc…
    – change the post sorting to use event start date or venue or any other additional field.

    So basically my front end template will have different functionality than the default post type of ‘post’…

    I guess I’m jumping ahead a bit here but just wanted to voice my thoughts :).

  19. MostlyBlog
    MostlyBlog Published |

    wow great post thanks for sharing with us

  20. vpsbul
    vpsbul Published |

    nice feature!

  21. The Real David Tufts » Blog Archive » Using Custom Post Types in Wordpress 3.0
  22. Nina
    Nina Published |

    Totally helpful. Thanks a lot 🙂

  23. life is real
    life is real Published |

    I’ve problem..How do custom posts such as categories and tags?

  24. WordPress 3.0-alpha – pasul către un CMS adevărat? | WP Tuts
  25. Iva
    Iva Published |

    Awesome tutorial, but what would I have to do if I wanted to query only one specific type in the sidebar? I tried your Query Posts widget to query all the items from a non-hierarchical category “song” and it’s impossible.

    And how can I assure that a custom post type will be page-like? I was trying to get rid of some things in the display on “song” post type and make it output values of certain custom fields by making it a custom template and I realised that it’s not possible, because it’s post-like, not page-like. Would creating a template file song.php result in anything by default? I thought this is what add_post_type_support() could do but I have not seen any references to that yet.

    I guess that I can’t wait for the rest of this series, as so many things are left unsaid and your and WP Engineer’s posts on this both left everyone curious. 🙂

  26. Bill Perciballi
    Bill Perciballi Published |

    We are going to kick-off a blog for our company. And, I’m curious as to why you chose WordPress over say TypePad or Blogger. What’s the advantage?

  27. Best WordPress Development Tutorials From February 2010
  28. Mediebureau
    Mediebureau Published |

    does this work with xampp? because i am using one i don’t if it will work.

  29. Mike Schinkel
    Mike Schinkel Published |


    Nice post, thanks.

    One thing though is that you example as written whacks out the new menu system since menu items are not custom post types. You should change it (I think) to

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

    That works for me but there may be an even more robust way to handle it.

    1. Rich
      Rich Published |

      Thanks Mike. My menu vanished after a very long session and this was a life saver!
      This solves it 100%

      1. Rich
        Rich Published |

        Actually this has now conflicted with something else. Is there a definative way of achieving this in WordPress 3.0 without loosing your custom menu?

      2. ivan.chaquea
        ivan.chaquea Published |

        Triying to achive this result, not on home but categories. im updating the code as i find out more, but still not working properly

        now the wp_nav_menu only conflicts on the category page, everything else is showing normal


  30. Marc Deschamps
    Marc Deschamps Published |

    Most usefull post, but still can’t wait for wp3.0 🙂
    I also agree with Jason Pelker, WP will become defacto CMS and still be easy to host it anywhere.

  31. Toeic
    Toeic Published |

    This is very helpful. Thank you very much. Are you going to write a bit more about it?

  32. illimar
    illimar Published |

    One thing I noticed with using the Wordpress dev version is that the edit post/page title has changed. It probaby is constructed something like this: “Edit $post_type”.

    This is bad, because it doesn’t take other more complex languages into account.
    For example, both finnish and estonian have over a dozen of different cases, and this is one of the places where they are used.
    For example, while editing a page, in estonian this would display “Muuda leht”, whereas it should be “Muuda lehte”.

  33. HeroicNate
    HeroicNate Published |

    What does it mean when you get: “Warning: Illegal offset type in isset or empty in /home/content/html/wordpress/wp-includes/query.php on line 1715”?

  34. links for 2010-03-28 | Links | WereWP
  35. Sam DeSocio
    Sam DeSocio Published |

    the thing I don’t understand is from a theme creation perspective how do we call these in a specific way. It seems like you did that in your screen shot but didn’t speak to it in the post.

  36. Trying to Add New Post Types | Go
    Trying to Add New Post Types | Go at |
  37. Daily Digest for April 24th
    Daily Digest for April 24th at |
  38. Wordpress 3.0 Insight – main features and settings
  39. fb
    fb Published |

    Once again another solution, to save us a lot of extra editing…

    Now if we could only sort out custom post_type archives that would be great.

    Keep up the great work

  40. Mark
    Mark Published |

    I really need to create a new set of pages right now in a 2.92 site. But if I were on 3.0 already, I’d want to make them a custom post type instead. But I’m hearing this is 2 weeks out at least.


    In 3.0, can I convert a normal Page to a Custom Post Type? Likely not in Admin, so if it’s not, would I just be able to go into the database and change the post type field to the name of the custom post type, from “Page?”

  41. Ted
    Ted Published |

    Its ok, but WP 3.0 now in beta, on front page i see only 2,9,2?

  42. Ovidiu
    Ovidiu Published |

    nice. now how can I convince the Leviathan theme to show the byline before the post and the post-meta after the post for my custom post types just like it does for regular posts?

  43. Ovidiu
    Ovidiu Published |

    oh, just noticed that the settings for Hybrid recipe settings, recipe being my new custom post type, are not saved when saving a new recipe. any idea what could be wrong here?

    Using wp 3.0 RC2 and your 0.8.1 beta hybrid theme + Leviathan

  44. Template Changes/Tags for Wordpress 3.0
  45. Damian
    Damian Published |

    If I create a custom post, how can I filter my query to a specific category?

    Let’s say a create a custom post type called ‘Music’ and I create 3 categories : ‘jazz’, ‘classical’ and rock. How can I only display the ‘jazz’ and ‘rock’ entries??

    This’s not wok query_posts('post_type=uslugi&cat=17,19'); ?

        'order' => 'ASC',
        'kat-uslugi' => 'Nasze Usługi', // how add more categories ??
        'showposts' => 4,
    $my_query = new WP_Query($args);
  46. Wordpress 3.0 Roundup | Themergency
    Wordpress 3.0 Roundup | Themergency at |
  47. Getting Down and Dirty with WP_Query->set() | Michael Fields: WordPress Development
  48. Adam
    Adam Published |

    I think this will work really good with the new wordpress 3.0. What do you think?

  49. Anna-Maria Eriksson
    Anna-Maria Eriksson Published |

    This doesn’t seem to work anymore with the final release of 3.0. I don’t know why, but I get a syntax error (in dreamweaver cs5) when I paste this code inside.

    I would like to have my CPT’s displayed in the main loop, just like this code snippet does, but for some reason it just doesn’t work anymore…

    Any ideas on why?

  50. Around the WordPress Community: HTML Emails, CSS3, Custom Post Types, Theme Design, and Taxonomies
  51. Michael
    Michael Published |

    This works great, but I’m running into a problem. Let’s say you use this to show every post type on your homepage. But in the sidebar, you want to list the last five posts of one particular post type. So you set up a get_posts loop with the post_type specified. It doesn’t work. $query->set overrides your get_posts argument and shows the last five of all post types. What would be the best way to circumvent this problem?

    1. Josh
      Josh Published |

      I had to change the post query just before the post loop. This allowed me to do exactly what you are trying to do. This also doesn’t break the WordPress menus. You can check it out at http://think2loud.com/?p=763

    2. Ryan Stang
      Ryan Stang Published |

      DId you find any solution to this? I’m struggling with the same problem.

  52. xefned
    xefned Published |

    It worked!
    Although for some reason I had to make my post type plural in the code

    'post_type', array( 'post', 'page', 'albumS'...
  53. Useful Resources and Tutorials to get started with WordPress 3.0 | ryanriatno
  54. Displaying custom post types on your WordPress blog homepage – Think2Loud
  55. helpin
    helpin Published |

    I entered the code in functions.php
    under function editoptions() {

    .But It doesn’t make any changes for any site in my multisite network. Am I missing anything?

    Thank you !

  56. Afficher les “Custom Post Types” sur votre blog et flux RSS ! sur Geekeries.fr | Découvrir WordPress
  57. Ami
    Ami Published |

    Just what I’ve been looking for but problem I have run in to a problem.

    All my posts show on the home page page as I wish but I also have a gallery page which I would only like to display my gallery custom post types.

    This is my code in page-gallery.php:

    If I remove Justin’s code from my function.php then the only the gallery posts will be shown on the page but no on my home page.

    Any idea’s? Or have I missed something?


  58. Renee
    Renee Published |

    Where would you change is_home()?

  59. Margarida
    Margarida Published |

    Hi there Justin,
    I have just started a new blog, and I am using a child theme for twentyten. I created two post types and noticed that they don’t show up at all. Even with a category assigned to them, they don’t show up in category page.
    So I inserted the code you gave here in my function.php, and post types already show up in my homepage, but I get this error:

    Warning: Illegal offset type in isset or empty in /home/magawork/public_html/criaturasblog/wp-includes/post.php on line 736

    Warning: Illegal offset type in isset or empty in /home/magawork/public_html/criaturasblog/wp-includes/post.php on line 736

    I have no idea what this means.
    Can you help me please?

  60. JeremyT.
    JeremyT. Published |

    Hi Justin, thanks for this code. I don’t pretend to fully understand it, but I will try to implement this feature. I like the flexibility of adding post type to the blog page.

  61. nickmorss
    nickmorss Published |

    Im getting the same issue as Ivan.

    I want to be able to show my custom Post types when i filter by category… Ivans code works but with nasty side effects



  62. Ovidiu
    Ovidiu Published |

    I currently use this code, as per your example to show different custom post types on my home page.

    /*show pages and recipes on home page */
    function my_get_posts( $query ) {
    if ( ( is_home() && false == $query->query_vars['suppress_filters'] ) || is_feed() )
    $query->set( 'post_type', array( 'post', 'page', 'recipe') );
    return $query;

    can you help me change the code to exclude posts from a certain category from being displayed?

  63. Jason
    Jason Published |

    I had a question about the sample screen shot at the beginning of the post. How would you have wordpress show the custom post type before the title like you do here? Also how would you style that?

  64. First Impressions of Custom Post Type | İslam BİLİK – İnternet Günlüğüm | MuLtitap
  65. Resources for Using WordPress as a CMS « MengelIT
  66. Jonathan Clarke
    Jonathan Clarke Published |

    Brilliant! Just what I was looking for. Now I don’t need to bother writing custom wp-query and templates to display custom post types. It really pays to read the codex to find these gems.

  67. Jonathan Clarke
    Jonathan Clarke Published |

    Having some trouble using get_adjacent_post with a home page that includes multiple post types. It looks like get_adjacent_post breaks.


    Is there a better way of getting previous and next post IDs from an index or archive template?

  68. Chris
    Chris Published |

    I’ve created a custom post type and a page using that type. In the reading options, I want to assign a static page made from this custom post type to be used as the home page, but there are only options for pages. Is there anyway to assign a page created with a custom post type to the home page?

  69. Justin Sternberg
    Justin Sternberg Published |

    i can’ t get page 2 of my category archives to load… all i get is a 404. See what i mean: http://spencerconstructioninc.com/wordpress/category/custom-home/page/2/

    the category.php code looks like this:

    any, 'paged' => $paged, 'posts_per_page' => 3) );
    if (have_posts()) : ?>


  70. Ovidiu
    Ovidiu Published |

    just tested and I see your page 2 !? how did you solve it? Just curios as I get a 500 server error when trying to view page 4 🙁 http://pacura.ru/page/4/ and I don’t have anything in my logfiles all I see is Premature end of script headers: index.php and )Connection reset by peer: mod_fcgid: read data from fastcgi server error

    but to be honest I don’t see the relevance to this post here 🙂

  71. Ovidiu
    Ovidiu Published |

    I don’t think it is related, just threw my comment in hoping the guy would give me some feedback. mine is:

    /*show pages and recipes on home page */
    function my_get_posts( $query ) {
    if ( ( is_home() && false == $query->query_vars['suppress_filters'] ) && !is_post_type_archive() || is_feed() )
    $query->set( 'post_type', array( 'post', 'page', 'recipe') );
    return $query;

    and I don’t think there is anything wrong with that 🙁

  72. anmari
    anmari Published |

    thank you for the article and to all commenters for their various input. A few points that may be relevant for others reading…

    1)I think that one also needs to consider the possibility of people using multiple plugins with different post types, and so one should not just “set” the post types of the query as one filter would override the other.

    One should fetch the posttypes set already for the query,

    if none, then it is only querying posts, start the array with ‘posts’, else you will lose the posts when you “set” the rest.

    then ADD your post types to what is already there?

    2) There is a homepage js slider out in the wild that pulls in extra “pages” to the homepage. Not adding “pages” to a home page filter similar to above “broke” the homepage. But you may not want new pages appearing in a feed… so be careful what post types you add where… code may need to be more selective.

    3) @Ovidiu, I gather is_post_type_archive() is a 3.1 feature only (not in 3.0.1?)

  73. Ovidiu
    Ovidiu Published |

    @anmari: sorry for not mentioning it, is_post_type_archive() comes from a plugin that offers a custom post types archive.

  74. How to use custom post types as events | amr ical events
  75. Custom Post Types in Wordpress 3.0 Links | Jason Lawton's Blog
  76. How to create Wordpress Custom Post Types | tutorials blogs
  77. Displaying Custom Post Types in Wordpress Blog @ GarethCooper.com
  78. 800A
    800A Published |

    I Justin.
    I’m using custom_post type and all it’s ok. Thank for your tutorials!

    There is a problem about SEO. When a news custom_post_type change status to published all pings to service list are not performed. So i added this code in my function.php

    function my_custom_pings($post_id){
    	wp_schedule_single_event(time(), 'do_pings', array($post_id));
    add_action('publish_movies', 'my_custom_pings');

    Whit this code all ping are performed as well, but miss something… need to flush the feed. I noticed that when i publish a movies post type feed are not refreshed, it refresh only when i publish native post type.

    Do you know how to do it?

    Sorry for my bad english. 🙂

  79. 800A
    800A Published |

    I found this ticket:

    bug fixed in 3.1 release

  80. thompson
    thompson Published |

    I’m using your code to add custom post types to my homepage. It works AWESOME, but when WordPress debug is set to true, it returns this notice:

    Notice: Undefined index: suppress_filters in /functions.php on line 162

    Is there a way to change the code to clean this up? It’s not a big deal, but I’m trying to clean up my code. Thx.

    1. Chris
      Chris Published |

      I got around this by doing this…

      function my_get_posts( $query ) {
      	$var = false;
      	if (isset($query->query_vars['suppress_filters'])){
            $var = $query->query_vars['suppress_filters'];
      	if ( is_home() && false ==$var ){
            $query->set( 'post_type', array( 'post', 'my_event') );
      	return $query;
      1. thompson
        thompson Published |

        BEAUTIFUL. That worked perfectly! Thank you.

  81. BenZ
    BenZ Published |

    When I use this piece of code in WP 3.03, it displays perfectly on the homepage. But when I’m assigning a page template for the custom post type to a page is displays all the custom posts like on the homepage. Is there a way to suppress that function allowing the display of selected custom posts only on the homepage while the other pages display only the assigned page template?


    1. thompson
      thompson Published |

      FYI Wordpress 3.1 will have built in templating to automatically create an index of custom post types at your ‘domain.com/slug’ of the custom post type. In case it helps.

  82. Rami
    Rami Published |

    You need to add ( ! is_admin() ) to IF.

  83. theWebalyst
    theWebalyst Published |

    A longshot: do you know how to make a custom post type for which is_page() with return true?

    I want the default handling of my custom post type to be the same as for Page rather than it be treated like a Post – but without having to modify the template (i.e. something the plugin which creates the custom post type can set).



  84. BenZ
    BenZ Published |

    Hi Justin, do you have an answer for my query? See my post above.


  85. elmalak
    elmalak Published |

    I really enjoyed this post and the codes works great on my home page.

    However, I am facing this issue with custom post types;
    I used tags for them but when I try to display tag pages, I keep getting not found, is there something I am missing here.

    I use a child theme of Twentyten for my site.

    Many thanks.

  86. Peterson
    Peterson Published |

    Hi Justin, I try this code on my website and it works fine. Thanks for sharing a good thing.

  87. Displaying Custom Posts on Home Page | English Advantage
  88. Jason Paul
    Jason Paul Published |

    Great function. I need to be able to customize how my Custom Post type archive looks as the homepage. Is there a way to tell it to only display, for instance, The title and thumbnail with a link to the post?

  89. Harish
    Harish Published |

    Hello Justin. great post.

    I had used your code on few of my websites.

    There is one issue am facing and tried to loopup and study all code but till now no solution.

    The pagination and everything works fine on my page which shows a list of custom post types (5 per page with next/previous links sorted by menu_order value).

    However when I try same code on another page, which shows individual items from a custom post type, the data is displayed, but the next & previous posts links seem to be sorted based on date and not “menu_order” even after having the query correct.

  90. HaiderEKarrar
    HaiderEKarrar Published |


    The code works for my main page.

    I have an Event custom post type. When I access ../events/
    both posts+event posts are displayed.

    I did an ugly fix and added

    if( $query->query_vars['post_type'] == 'event') 
      return $query->set('post_type', array('event'));

    I rather filter on category but category is “”

  91. Mark
    Mark Published |

    Hi very interesting article. I have a problem to display the type of posts like on the screenshot. I want to display, if the post is a custom post, the post type name and then the title. Can anyone help me?

  92. Dominic
    Dominic Published |

    Hey Mark,

    for example you can ask in the loop of your index.php what type the post is and if the post is a custom post type you can display your custom name:

    ID ); 
    if ($post_type == 'movies') {
    echo 'Movie: ';  }

    Another way is to display the singular name of the custom post type:

    echo $post_type->labels->singular_name;

    I hope I could help you

  93. Dominic
    Dominic Published |

    I think I made ​​a mistake. The code was not displayed correctly. The right codes snippets are:

    To ask in the loop if your post is a custom post and display a custom name:

    $post_type = get_post_type( $post->ID ); 
    if ($post_type == 'movies') {
    echo 'Movie: ';  }

    To display the singular name of the custom post type:

    $post_type = get_post_type_object($post->post_type);
    echo $post_type->labels->singular_name;

    You have to paste it in the loop at your index.php. I hope this time it displays it correctly.

  94. Dan
    Dan Published |

    What I don’t get is that for a homepage you would want


    But in custom post types you have to create a slug or use the default. So a custom home page post type would only allow something like http://www.mysite.com/home?

    Is that correct?

  95. Dan
    Dan Published |

    Could you use a custom post type as static page for your home page with this?

  96. Playing with WordPress custom post types : Suzie Blackman
  97. Adrien
    Adrien Published |

    I have a website where several pages show the loop, but depending on the page, only one kind of post is shown (e.g. in the “Issues” page, only the ‘issues’ custom post types show).

    In this example, “is_home()” is used in an if-statement to test if you’re in the homepage right?
    Could I use a similar method to do what I mentioned above? Or is there a simpler way to do it?

  98. Amado Martinez
    Amado Martinez Published |

    Great! Exactly what I was looking for!

    @adrien yes you can do that, use is_category() or is_page() or something similar along with get_queried_object to find the category or page id and decide which post types to display.

  99. Raquel Patro
    Raquel Patro Published |

    This code comes into conflict with bbPress. Only on the homepage, the code makes the custom post types are listed in the list of forums (widget).

  100. Create Custom Post Types and Taxonomies on Wordpress | Abigail Abanilla
  101. Jerry Lee
    Jerry Lee Published |

    Hey, I am really interested in using this, and was able to get it setup for cars, (make, model, year, etc.), but now how do I get it to display on a page? I am building a website for a car lot, and need to be able to add the car details through the post types, and then have each car print out on the page with the custom post types I added. I know this is probably a silly question, but I am just not used to custom post types, and I know they have a lot of power.

  102. How to display only top level posts in loop via WP_Query? | SeekPHP.com
  103. A Free wordpress newsletter » WordPress Custom Post Types Tutorials, Tools & Advice
  104. A Free wordpress newsletter » WordPress Custom Post Types Tutorials, Tools & Advice
  105. James
    James Published |

    How can I display custom meta date on a page that displays a custom post type?

    1. James
      James Published |

      I mean data

  106. James
    James Published |

    Okay, Actually I mean custom field data. I am getting frustrated.

  107. url rewriting for most recent post | SeekPHP.com
  108. Download Wp Themes Stereoline Magazine – WordPress 30 in 1 » Theme Forest
  109. Thewayitis
    Thewayitis Published |

    if I changed ‘if ( is_home()..’ to ‘if (is_page(144)…’.

    it’s not working?

  110. Holly
    Holly Published |

    OK folks. If you’re having trouble getting Justin’s code to play nicely with your navigation menus.

    The following is the only solution I found that allowed me to use the code Justin provided here without either a) wiping out navigation menu items, or b) including navigation menu items but then having the menu items show up as though they were posts (which, let me tell you, looks extremely stupid)…neither of which is at all an acceptable solution.

    1) Follow Justin’s directions to include the custom post types on your homepage.
    2) To get the navigation menu items to reappear:
    As some others have suggested, add ‘nav_menu_item’ to your array of custom post types in the code Justin has provided.
    3) To prevent navigation menu items from also appearing within the loop as if they are posts:
    Just inside of the loop, add an if statement to exclude the nav_menu_item post type.

    For example, at the beginning of the loop:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); //beginning of loop
     if('nav_menu_item' !== get_post_type()) : // ADD THIS LINE  Exclude navigation menu items.
    // rest of your loop code 

    and at the end of the loop:

    Hope this is helpful to someone.

    1. Holly
      Holly Published |

      I screwed up the code tags in my previous reply, thus mangling my entire purpose for posting! I’ll just paste it as normal text here, forgive me.

      At the beginning of the loop:

      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); //beginning of loop
       if('nav_menu_item' !== get_post_type()) : // ADD THIS LINE  Exclude navigation menu items.
      // rest of your loop code

      At the end of the loop:

  111. Holly
    Holly Published |

    Oh for God’s sake, I solved the problem but now I cannot post a simple comment without half of it disappearing. Such has been my day. One last try here lest I screw things up for folks more than they already were.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); //beginning of loop
     if('nav_menu_item' !== get_post_type()) : // ADD THIS LINE  Exclude navigation menu items.
    // rest of your loop code 

    and at the end of the loop,

    <?php endif; //ADD THIS LINE

    (plus of course add closing php tag but I think that was causing my code to get stripped out, so I omitted it here).

    1. Jeremy Ferguson
      Jeremy Ferguson Published |

      Holly Thanks! Yours is the best of all of the code I’ve tried. It still breaks the recent posts widget but I can live with that for now.

  112. BlacksAngel
    BlacksAngel Published |

    If i have 2 custom post types like Movies and Series
    What is the solution for this script ?

     'post_status' => 'publish',
     'paged' => $home_paged
  113. Part 2: WordPress Custom Field vs Custom Post Type vs Custom Taxonomy
  114. Frank Catanzaro
    Frank Catanzaro Published |

    I am looking for a simple way (short code ?) to list all of the “Article” post type on my site in a regular blog post. Reason being that I am using the Onswipe iPad plugin and it only shows regular posts, not pages or other post types. I would like to at least be able to show the list of Articles on the site to iPad viewers.

  115. Andrej
    Andrej Published |


    Excellent tutorial, exactly what I searched for. With several tweaks to the if statement I got desired results.


  116. Valerie Lynn
    Valerie Lynn Published |

    Justin, thank you for your tutorial. I’ve been wracking my brain trying to get my one little Custom Post Type to show up on the front page of my blog and if it weren’t for you and Otto, I’d still be chasing my tail. I appreciate the clarity.

  117. Matt Kettlewell
    Matt Kettlewell Published |

    Justin –

    I’m using a CPT of ‘recipe’

    If I use post types of ‘post’ and ‘recipe’ , I get the content of the recipe, but not the proper formatting…

    If however, I use post types of ‘post’, ‘recipe’ and ‘PAGE’ I get the proper formatting of the recipe CPT, but then I’m also getting actual pages listed…

    Thoughts, Tips or Ideas?



  118. Adam
    Adam Published |

    events aren’t posts, they are custom posts. You can use standard WP hooks/filters to get custom posts to appear on your homepage, e.g. http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page

    I was directed here and I’m hoping someone can help me Im using the plugin Events Manager on wordpress which creates events as custom posts. I want these posts to be assigned a normal wordpress category I’ve created and to appear within the category if someone was to say browse that category.

  119. Random Jane
    Random Jane Published |

    Thanks! Tried it and it worked 🙂

  120. Vino Divas
    Vino Divas Published |

    Thanks. Tried it and it worked 🙂

  121. arun sameer
    arun sameer Published |


    i have created 3 custom post types with separate taxonomies and i was able get the three custom post types in loop… for 3 custom post types there is a category featured now i need to display only posts of 3 custom posts which has featured category selected

    here is my code its not working

     'automobile', 'category' => 'featured', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
  122. arun sameer
    arun sameer Published |

    sory for reposting forgot to add pre tag

    here is my code

    'automobile', 'cat-automobile' => 'test', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
  123. Rositsa 'roz' Zaharieva
    Rositsa 'roz' Zaharieva Published |

    You just saved me, LOL 🙂 We had an issue here at work with the pagination of a such mixed loop of posts and a custom post type that I couldn’t resolve no matter what I tried (and I’ve been trying for days and days now, since it is a big project and it’s quite important that everything’s fine).

    Thank you!

  124. Network Marketing System
    Network Marketing System Published |

    Wow… Just copy and paste and it’s that simple… I’m going to try this out now. Hopefully I won’t jack up my functions.php file lol

    – JL

  125. Jason Newonski
    Jason Newonski Published |

    Thanks for the article – you’ve saved me some time and some hair! I’ve been looking all over for this.

  126. Wordpress the_content not working with custom post type | BlogoSfera
  127. Paolo Appley
    Paolo Appley Published |

    This is great, but I’m running into a problem. I’ve also added custom fields to my custom post type via “Advance custom fields” and none of the content inside the custom fields shows up. Can’t figure how to make sure the post is pushing all that content to the homepage/feed

    1. Paolo Appley
      Paolo Appley Published |

      Sorry, answered my own question, but am posting just in case anyone ran into this.

      You have to call the content of the custom fields through the custom fields functions. In my case it was the_field(‘custom field’).

  128. Rehan
    Rehan Published |

    Sorry for my ignorance

    I have installed Custom Post Type UI version: 0.8 and after i created New Custom Post Type called FAQ. After refreshing I got a new tab FAQ under comments in the admin interface.

    FAQ – FAQ
    Add FAQ

    I added some of my posts and i could view it perfectly like below


    What i want is to show all FAQ post which i have created under one menu item

    I tried to access http://localhost/Experiment/faq/ it gives a 404 error

    What i don’t understand is after installing the plugins do i need to edit the files.
    If so which files i need to edit what code i need to insert.

    All code given above is in parts could you make it in a single page please mention precisely where i should add and which files.

    How can i show all FAQ post type not other posts as a blog and how to assign a link to menu?

    Thanks in advance

  129. Custom Content Types y Custom Taxonomies en Wordpress | Max Villegas
  130. david ruiz
    david ruiz Published |

    Hi! it works! thanks .

    I´m triying to show each post type in a individual template page.

    What should I do to show, the movie post type in a created template page, like content-movies, or single-movies?? Could anyone help me?thanks!

    1. demetriusPop
      demetriusPop Published |

      This is a cool pattern to use:

      I got this from Wordpress 2.8 Themes Cookbook. Lots of Patterns in that book.

      Create a category for your custom post >

      Place the code in the template file you want to use(make sure to select that template in the admin panel)

      Now, only post of the selected category will show up on that template.

      1. demetriusPop
        demetriusPop Published |

        Sorry, the code is:

            $cat = 'Your Category Name Here'));
            if(have_posts() ) {
                while(have_posts() ) {
  131. demetriusPop
    demetriusPop Published |

    Thanks man, works perfectly!!!

  132. misyaath
    misyaath Published |

    I want to add more than one post type in one archive page but it does not can you help me some one please

  133. chris
    chris Published |

    Hi Justin,

    I love your posts and your book (Professional Wordpress Plugin Development)

    I am using a custom post type for populating content for the jquery cycle 2 plugin. All is working well except that my output posts are stripped of html? An hour of google searches has taken me into a dizzying rabbit hole of wordpress functions custom post functions and I’m hoping you can shed some light on why the posts are stripped and what one can do to preserve the input tags?

  134. Sergio
    Sergio Published |


    I was linked to your page through the Custom Post Types UI Plugin page and i have been having some issues getting my new “Post Type” to display on my Category List Plugin. Firstly, i am very new to coding of any sort but i have tried to understand as much as possible so forgive if i show any ignorance. According to The CPT UI plugin i added these snippets of code to my function.php file :

    add_action('init', 'cptui_register_my_taxes_positions');
    function cptui_register_my_taxes_positions() {
    register_taxonomy( 'positions',array (
    0 => 'post',
    array( 'hierarchical' => true,
    'label' => 'Positions',
    'show_ui' => true,
    'query_var' => true,
    'show_admin_column' => false,
    'labels' => array (
    'search_items' => 'Position',
    'popular_items' => '',
    'all_items' => '',
    'parent_item' => '',
    'parent_item_colon' => '',
    'edit_item' => '',
    'update_item' => '',
    'add_new_item' => '',
    'new_item_name' => '',
    'separate_items_with_commas' => '',
    'add_or_remove_items' => '',
    'choose_from_most_used' => '',
    ) );
    add_action('init', 'cptui_register_my_cpt_draft_posts');
    function cptui_register_my_cpt_draft_posts() {
    register_post_type('draft_posts', array(
    'label' => 'NFL Draft Posts',
    'description' => '2014 NFL Draft Prospects',
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'capability_type' => 'post',
    'map_meta_cap' => true,
    'hierarchical' => true,
    'rewrite' => array('slug' => 'draft_posts', 'with_front' => true),
    'query_var' => true,
    'has_archive' => true,
    'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
    'taxonomies' => array('category'),
    'labels' => array (
    'name' => 'NFL Draft Posts',
    'singular_name' => 'Draft',
    'menu_name' => 'NFL Draft Posts',
    'add_new' => 'Add Draft',
    'add_new_item' => 'Add New Draft',
    'edit' => 'Edit',
    'edit_item' => 'Edit Draft',
    'new_item' => 'New Draft',
    'view' => 'View Draft',
    'view_item' => 'View Draft',
    'search_items' => 'Search NFL Draft Posts',
    'not_found' => 'No NFL Draft Posts Found',
    'not_found_in_trash' => 'No NFL Draft Posts Found in Trash',
    'parent' => 'Parent Draft',
    ) ); }

    Then i followed your instructions above and added this to my functions.php file as well:

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    if ( is_home() && $query->is_posts_page )
        $query->set( 'post_type', array( 'post', 'page', 'draft_posts' ) );
    return $query;

    I can view the post when i click the “view post” link but i just can’t seem to display it on my home page. If you look at the bottom of my website home page i have a section labeled “NFL Draft” but nothing appears. To clarify, i don’t want it to be in the regular loop, i actually want it to just be displayed on my “Category List” widget or “Featured Category” widget. Any suggestions or direction would be very appreciated!

    1. Gary
      Gary Published |

      I was getting a similar problem, followed the tutorial, added the register_post_type and the pre_get_posts filter

      I could see my list of posts but clicking through to them gave me nothing…

      turned out it was a permalink problem, going to the settings>permalink and just clicking save fixed it for me 🙂

  135. klikharry
    klikharry Published |

    Great function. I need to be able to customize how my Custom Post type archive looks as the homepage.

  136. ALejandro B
    ALejandro B Published |

    I am using you CPT UI and in the post i do not have a categories, but I would like to display my post in order=ASC. But since i do not have categories, I cannot do that. Is there a way for me to add categories to the post_type_folder?

    <?php if (have_posts()) :?>
    <?php while (have_posts()) : the_post(); ?>

    <?php the_content();?>

    <?php endwhile;?>
    <?php endif; ?>

  137. laishaoyi
    laishaoyi Published |

    this article really help me a lot.

    i was dealing with querying category archive pages for custom post type.

    really big thanks!

  138. John Ellis
    John Ellis Published |

    Wow – the easiest, fastest, most successful thing I have done in WP yet and you made it a snap. Everyone else had much more complicated ways than this. I shall be looking here for more solutions.

    Respect, and thanks!

  139. Susana
    Susana Published |

    I know this is 3 years old, but it continues to be one of the top (and best) search results I’ve been able to find on this topic. I implemented the code and it worked, however I want the custom post types to show up on category and tag archive pages as well.

    A little research has led me to believe that I need to use is_category, but since I am very new at this I’m not sure how to implement it. I played around and got it to work with the following code, but then it caused my primary menu to disappear! (Only on the category archive, not homepage, though) Any ideas why? The category.php template includes the header just like every other template.

    Here is the code in my functions.php:

    // Show custom post types

    add_filter( ‘pre_get_posts’, ‘my_get_posts’ );

    function my_get_posts( $query ) {

    if ( is_category() xor is_tag() xor is_home() && $query->is_main_query() )

    $query->set( 'post_type', array( 'post', 'review' ) );

    return $query;


    Any suggestions would be greatly appreciated!

    1. Susana
      Susana Published |

      For anyone else you might stumble across this, I’ve found a solution to the disappearance of my menu!

      I’m not exactly sure why it works because I’m sort of stumbling through this blindly since I don’t know PHP, but I think it may have to do with the fact that Nav Menu is actually a post type as well.

      Here is the code I ended up with:

      // Show custom post types

      add_filter( ‘pre_get_posts’, ‘my_get_posts’ );

      function my_get_posts( $query ) {

      if ( ( is_home() xor is_tag() xor is_category() ) && $query->is_main_query() )

      $query->set( 'post_type', array( 'post', 'review' ) );

      return $query;


      Hope that can help someone else out there!

  140. Alexey
    Alexey Published |

    One thing I don’t understand is how to display list of custom post types on a custom page.

    Let’s say we have custom post type movies. So obviously /movies will be archive for my movies.

    But what if I want it to be a page, so I can add text and images and the show list of movies. Is this possible at all?

    I haven’t found any tutorial to explain that

  141. jamie
    jamie Published |

    How do I go about getting the custom post type to recognize the formatting of a custom template on the homepage? I have my content showing on the homepage. I have a plugin that allows me to select a custom template just like regular pages but when the content shows up on the front page, there is no custom formatting.

  142. Glamorous Bite
    Glamorous Bite Published |

    Hi, does it effect the value of the pages if they are custom types?

    Thanks 🙂

  143. Ben Townsend
    Ben Townsend Published |

    Thanks Justin. The code snippet for functions.php worked like a charm!

  144. Keith Melvin
    Keith Melvin Published |

    How do I get the custom posts to appear in loops across the whole site? The code above works for archives but I would like it in recent posts widgets etc. Thanks

  145. Tia
    Tia Published |


    The post was helpful and very easy. However, i’m facing lot of issues with categories while managing WB posts. Posts are messed under different categories. Can you please help me.

  146. cedric
    cedric Published |


    Is there a way to make this work for WP multisite ? I have this error :

    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’, ‘recipe’ ) ); return $query; }

    Fatal error: Cannot redeclare my_get_posts() (previously declared in /home/icinge5/public_html/paleo-optimal.com/wp-content/plugins/functionality/functionality.php:20) in /home/icinge5/public_html/paleo-optimal.com/wp-content/plugins/anual-archive/annual_archive.php on line 11

    Also I assume functionnality plugin doesn’t work with WP MU.



  147. Simon
    Simon Published |

    Humm. I want my custom post to look different to the other posts on my home page, to have a different background (actually I want transparent) but my custom post looks just the same as all the others in my feed.

    Do you have any idea what I’m doing wrong / missing?

    Many thanks in advance.

  148. CPT (Custom Post Type) WordPress | blog-note
  149. Simon
    Simon Published |

    This is so unobvious it’s unreal. Thank you sir, you’ve ended this long bout of frustration at Wordpress.

  150. thomas chang
    thomas chang Published |

    A good tutorial can last a long time!

    Thank you very much for sharing your knowledge.

    I’ve found your tutorials very helpful.

  151. Jack
    Jack Published |

    Even tough this is a very old post , still was helpful for me.


  152. WordPress Custom Post Types Tutorials, Tools & Advice
  153. John davis
    John davis Published |

    Hello really quick question I changed my latest posts to a static page posts page called blog in WordPress reading settings which works fine. I created a custom post type that I want to include with the other posts. I am following a video and it only shows it working on is_home. How do I get it to work with my setup of a blog page with the code the video provides?

    function my_add_reviews ( $query ) {

    If ( ! Is_admin () && $ query->is_main_query () {

    if ($query->is_home () || $query->is_search () ) {

    $query->set (‘post_type’, array (‘post’, ‘reviews’ ) );



    My browser says the error is on line 3 I am assuming is_home is the problem but changing to is_blog didn’t work. Please he,p thanks in advance have a great day.

  154. xmedia
    xmedia Published |

    I’ve created a custom post type and a page using that type. In the reading options, I want to assign a static page made from this custom post type to be used as the home page, but there are only options for pages. Is there anyway to assign a page created with a custom post type to the home page.

Comments are closed.