Articles in this series

424 Responses

  1. Michael
    Michael April 29, 2010 at 10:31 am | | Reply

    Awesome Post! Thanks Justin.

  2. Jake Spurlock
    Jake Spurlock April 29, 2010 at 10:36 am | | Reply

    Great write up, love how simple this whole process is now.

    I have a bunch of ideas stewing about what to do with this…

  3. Ryan
    Ryan April 29, 2010 at 10:39 am | | Reply

    Thanks for the rundown on custom post types Justin, it’s much appreciated :)

  4. Jeriko
    Jeriko April 29, 2010 at 10:41 am | | Reply

    What happens to posts with a custom post type, if the according plugin or theme’s deactivated? Will they be treated as regular posts instead?

  5. Shawn Hesketh
    Shawn Hesketh April 29, 2010 at 10:43 am | | Reply

    Thanks for this timely and in-depth article. I needed this information right now for a client site who wants to create a directory site for bands, listing their profiles. I’m in over my head, but this article will help. Thanks again!

  6. Jean-Baptiste Jung
    Jean-Baptiste Jung April 29, 2010 at 10:44 am | | Reply

    One of the most interesting tutorials I have seen in a while. Thanks a lot!

  7. Brad Williams
    Brad Williams April 29, 2010 at 10:52 am | | Reply

    Excellent post Justin! For anyone wanting to play with custom post types but not comfortable writing code check out my custom post type UI plugin:

    http://wordpress.org/extend/plugins/custom-post-type-ui/

    1. Idealien
      Idealien April 29, 2010 at 2:28 pm | | Reply

      There is also CMS-Press which does a lot of the same as the plugin you mention. Both allow you to create taxonomies and assign them to any post type you create. Neither, to my knowledge, yet allow you to do the same for meta boxes which would be a sensational aspect to add.

      In both cases I think that proving the concept of UI based management for post types, taxonomies and meta boxes via plugin is important, and equally something that should make its’ way into core (or canonical at the very least).

  8. Matthew Simo
    Matthew Simo April 29, 2010 at 11:13 am | | Reply

    Great write up Justin, got me re-excited about custom post types in 3.0…

    Time to do some more playing!

  9. Ben
    Ben April 29, 2010 at 11:28 am | | Reply

    Great tutorial. This is definitely one of the most exiting features of 3.0.

    Ultimately it’s the user that will benefit from this because as themes developers we wont need to set complicated metadata up and explain how to use them, we will just create the appropriate post type that will handle everything seamlessly.

    Let the “CMS” die and bring up the “Framework”.

  10. Andreas Nurbo
    Andreas Nurbo April 29, 2010 at 12:14 pm | | Reply

    Excellent. Been looking forward to this post.
    Great work

  11. Jeffro
    Jeffro April 29, 2010 at 12:26 pm | | Reply

    First off Justin, excellent guide. I also like the idea of calling them custom content types. However, even after this guide, I still don’t get it. I hear people describe custom post types and all I can think about is why not use categories, tags, etc as they seem to address the problem already. What are the differences between using that and this custom post type stuff? I don’t understand the limitations of how the current system works via pages, posts, etc versus custom post types.

    1. rgregory
      rgregory May 3, 2010 at 10:28 am | | Reply

      I recently created a site for a horse farm using wordpress. They list all the horses as posts, and the owner can’t create the new listings as she has SEVERELY limited computer skills. Each horse needs birthdate info, breed, and heritage info.

      Now I can create a new post type with info boxes for the Name, birthdate, breed, heritage and other info. She can fill these in and I can output a nicely formatted ‘post’ for her without her being able to mess up the formatting.

      This also allows news posts to continue without interruption.

  12. Jason Rhodes
    Jason Rhodes April 29, 2010 at 12:38 pm | | Reply

    Been waiting for this for a very long time. Thanks for the detailed write up.

  13. paul
    paul April 29, 2010 at 12:43 pm | | Reply

    Justin

    when you create new post types, do they get stored in the posts table?
    if that’s the case, I don’t think it’s very efficient for any kind of database driven application.
    If you’re using a relational DB, then it should use normalization, primary and foreign keys,etc…
    I think that’s something that PODS does.
    for example, if you have movies, actors, genres, etc… how is this translated to the DB schema?

    1. Otto
      Otto April 29, 2010 at 1:33 pm | | Reply

      Actually, normalization of database schema is slower. By a long shot. Many table JOINs are expensive as heck.

      The purpose of normalization isn’t efficiency; the purpose is for data integrity. When your data is normalized and you have proper foreign keys and constraints and such, then it’s possible to ensure that you never enter invalid data.

      In this case, that’s not the primary goal, because most any type of data you could enter would be valid. So efficiency and speed-wise, it’s faster to store all the posts (regardless of type) in the same place. Good indexing solves the speed issues. And your JOINs are greatly reduced when you’re not having to pull from multiple tables to retrieve multiple types of things.

      1. paul
        paul April 30, 2010 at 7:41 am |

        yes I suppose data retrieval is more efficient, and that’s how it’s done with data warehouses, where all data is in one table for faster queries.

      2. Matt
        Matt May 5, 2010 at 2:42 pm |

        As a developer on the Pods CMS project, Otto is *half* right.

        Yes, it’s usually quicker if you can avoid using joins. Custom post types by themselves don’t need joins since they’re in the posts table.

        However, custom fields do require table joins…

        I’ll go out on a limb and say that a lot of people are going to want a unique set of custom fields for each post type. Not only that, but they’ll want to filter based on one or more of these custom fields.

        For example, for an “Event”, you may need custom fields for latitude, longitude, end date, address, speakers, etc. What if you only want to show events within a certain lat/lng range?

        For these situations, Pods is *vastly* more efficient since you’re only querying a single table. With Pods, all the (non-relationship) fields for an event are stored in a single row.

        On the other hand, WP needs to JOIN with the postmeta table (at least once). Since postmeta data is always LONGTEXT, indexing is a huge challenge and the data isn’t subject to any MySQL optimizations.

  14. Dean McCean
    Dean McCean April 29, 2010 at 12:43 pm | | Reply

    Hey Justin, I just started with wordpress and tried to figure that out by myself – No way! Thank for thi great solution, nice tutorial ;

  15. John Myrstad
    John Myrstad April 29, 2010 at 12:58 pm | | Reply

    O`Reilly still havent called you ?

  16. Andy
    Andy April 29, 2010 at 1:10 pm | | Reply

    Awesome tutorial. One thing I frequently use wordpress for is basic e-commerce. Usually I use pages as products with a custom template and custom fields for things like prices. Is there anyway I can add an extra input box for “price” rather than forcing the user to to use the slightly more confusing custom fields? I don’t really care if the data is stored in a custom field, I just want the boxes to be easier to understand.

    Also, how can I make a custom post type default to a specific template rather than forcing the user to keep selecting one?

    Thanks foe the awesome tutorial!

    1. John Myrstad
      John Myrstad April 29, 2010 at 2:00 pm | | Reply

      ….Since this is a “custom” post type, I’ll assume you want to customize how it’s output. To overwrite the default, you can create a custom template. Our template will be called single-super_duper.php.

    2. Idealien
      Idealien April 29, 2010 at 2:33 pm | | Reply

      Andy – Check out this tutorial on creating meta boxes with custom post types. The data is still stored in custom fields but it shows up in the admin area in code-defined ways. So you could have price, inventory, available sizes, etc all within a “product details” meta box that goes along with the standard description + photos in the editor window.

      All stuff you *could* do before 3.0, just a lot easier to explain and tailor to terminology clients are familiar with now.

    3. Rilwis
      Rilwis April 29, 2010 at 4:50 pm | | Reply

      To add a custom meta to a post, even in custom post type, you can see an easy way in this tutorial. It’s easy to define and create some additional meta data for posts.

    4. Hayden
      Hayden June 3, 2010 at 1:30 pm | | Reply

      @Andy Idealien is correct. You could create meta boxes. I would also look into creating taxonomies for better content organization.

  17. Brad Potter
    Brad Potter April 29, 2010 at 1:15 pm | | Reply

    Thanks so much Justin. Lots of great information there.

    Jeffro – For me, I think the power of custom post types is that you can control which panels appear on the edit screen based on the type of content the end user is adding. Imagine creating a site for a client that needs an event log and customer contacts. Events & Contacts could be 2 new content types each with edit screens tailored for the type of content being added. The edit screen would have less clutter and would be less confusing to end users whose job is to simply add content.

  18. Danny G Smith
    Danny G Smith April 29, 2010 at 1:29 pm | | Reply

    I am beginning to get into them in a big way and am very to happy to see this post. The codex is slim right not on all of the options. It looks to me like the power will be in adding other content types as well, and I am not finding a lot of details on that. I am going to take a look at wp-includes/post.php and see if that sheds any light.

    thanks for all you do!
    Danny

  19. Matt Wiebe
    Matt Wiebe April 29, 2010 at 1:50 pm | | Reply

    Great work explaining things here Justin. A lot of this should be copy & pasted into the Codex entry for register_post_type()!

    One of the big gaps in custom post types is the lack of a proper landing page index for your post type. (eg http://yourdomain/super_duper/) I made a helper class for that in my post Smarter Custom Post Types in WordPress 3.0.

    1. Idealien
      Idealien April 29, 2010 at 2:40 pm | | Reply

      @MattW – Another option is to create a page template (page-{posttype}.php) that has a separate loop and display the contents of the post type as Justin has demonstrated above. This would be closer to using category-##.php if you were using posts / categories to achieve the same result prior to 3.0. The rewrite => ‘slug’ option even allows you to have ‘/toplevelpage/subpage/reallydeeppage/’ as the permalink so that you could have all your custom data types show up within the same area that you have the page permalink. This might require your settings -> permalink to be /%postname%/ I think.

      I’m very happy that this has come to core with 3.0. If nothing else it means that I can stop development for my Category Enhancements plugin (http://wordpress.org/extend/plugins/idealien-category-enhancements/) as the ability to use single-{posttype}.php and page for collection display is really all that it offered.

      1. Matt Wiebe
        Matt Wiebe April 29, 2010 at 2:45 pm |

        Indeed, the page template idea would work fine. But you wouldn’t get pagination with it, or feeds, which my helper class gives you.

  20. Vehicle Transport
    Vehicle Transport April 29, 2010 at 3:39 pm | | Reply

    Do you have a screenshot of what the finished product would look like? I’m in the middle of working with a Wordpress-based website that I’m creating, and I am discovering that to convert my blogger blog to the Wordpress site has really messed up my blog posts…Is there any easy way to fix this without having to re-write each one?

  21. Jan Egbert
    Jan Egbert April 29, 2010 at 3:41 pm | | Reply

    Wonderfully written Justin.

    It’s time for a big ‘Find & Replace Operation’ in everything that has ever been written about WordPress. Because it’s so much more than blog software.

  22. Danny G Smith
    Danny G Smith April 29, 2010 at 3:49 pm | | Reply

    Is that the reason I get a 404 when I run this code? My theme has a single.php.

    $carousel = new Carousel;
    
    add_action('init', array($carousel, 'carousel_tax'),  1);
    add_action('init', array($carousel, 'carousel_type'), 2);
    
    class Carousel {
    
       function __construct() {}
       function __destruct()  {}
    
       function carousel_type()
       {
          register_post_type('featured', array(
             'label'                 => __('Carousel Posts', 'carousel-container'),
             'execute_from_search'   => true,
             'public'                => true,
             'capability_type'       => 'post',
             'hierarchical'          => false,
             'supports'              => array(
                   'title',
                   'excerpt',
                   'editor',
                   'thumbnail',
                   'revisions',
                   'custom-fields'
                   ),
             'taxonomies'            => array('post-tag', 'category', 'carousel-tax')
             )
          );
       }
    
       function carousel_tax()
       {
          register_taxonomy('carousel-tax', 'carousel-container', array(
             'hierarchical'    => false,
             'show_ui'         => true,
             'label'           => __('Page where Carousel Posts will show', 'carousel-container')
             )
          );
       }
    }
  23. Doron Orenstein
    Doron Orenstein April 29, 2010 at 6:04 pm | | Reply

    I’ve really enjoyed using Magic Fields up until now, and supposedly, this makes Magic Fields obsolete.

    However, I’ve run into a couple of roadblock here as far as doing client work:

    1) I liked how Magic Fields made it really easy for clients to upload images into the custom fields instead of having to perfectly type a long and ugly URL. Looks like using Custom Post Types is a downgrade in that this functionality is now lost

    2) If a site is using a home page slide show for blog posts and I want to mix some of my new Post Types in with the blog posts for the homepage slide show, even if I add the correct category using the Custom Taxonomy, my theme is not registering the custom posts as a regular blog post, so there does not seem to be an easy way to have these posts appear on the homepage slideshow.

    If anyone has any ideas of how to overcome these 2 issues, that would be great.

    Either way, thanks for the great post Justin!!

    Doron

    1. Doron Orenstein
      Doron Orenstein April 29, 2010 at 8:03 pm | | Reply

      OK, so I’m now able to get my new custom posts working with my homepage slideshow as these new custom type blog posts are being mixed in with my regular blog posts.

      The instructions are here:
      http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page

      Still curious about creating a more elegant back end for the client to upload images into like I had with Magic fields, any leads would be awesome!

      Thanks!

      Doron

  24. Hobbsy
    Hobbsy April 29, 2010 at 6:20 pm | | Reply

    Great article Justin. I’m sure this is going to come in real handy

    A small aside, and I could be wrong here, but is there a slight typo in the code?

    should the code in the grey code for singular_label be

    'singular_label' => __( 'Super Duper' ),

    instead of

    'label' => __( 'Super Duper' ),
  25. Danny G Smith
    Danny G Smith April 29, 2010 at 6:57 pm | | Reply

    Ok, just got email back from wp-testers, be sure to regenerate your permalinks after adding new custom posts, or you may not be able to see them, that was my problem above.

  26. are jay
    are jay April 29, 2010 at 8:58 pm | | Reply

    Could something like this be used to allow for publicly submitted events to go into a moderation queue?

    Or know of anything?

    Thanks.

    1. Jan Egbert
      Jan Egbert April 30, 2010 at 9:34 am | | Reply

      I’m using Gravity Forms + custom post types to let users suggest their own events. Gravity Forms lets me set publish_status to Draft and although right now you need some basic coding skills , I’m sure Gravity Forms will have full support for custom post types and taxonomies very soon.

      1. Mikey Leung
        Mikey Leung July 28, 2010 at 9:53 pm |

        Yes, I think the Events Calendar has a lot of potential to roll out events-based websites. The problem is that it is still immature and has a few bugs, but I see the developers working very hard on getting this up to speed.

  27. Todd J. List
    Todd J. List April 29, 2010 at 9:52 pm | | Reply

    Thank you for such a detailed description. I’m starting to get excited for WordPress 3.0. I’ll have to chew on the possibilities here for a while.

  28. Stephen Cronin
    Stephen Cronin April 30, 2010 at 12:42 am | | Reply

    Great write up Justin,

    Hope you can follow up with more on this topic.

    For me, Custom Post Types are really only useful when you can search for things via the custom taxonomies (and more than one at the same time).

    Using the Movie DB example, I’d want to give the users a search where they can specify the actor name and the genre. eg: find me movies with actor=”Matt Damon” and genre=”Espionage”.

    I haven’t looked into how to do this yet, but it seems no one has either. If you know how, I’d love to read how!

  29. Andrew
    Andrew April 30, 2010 at 2:24 am | | Reply

    Will be bookmarking this really nice and helpful tutorial. Thanks so much!

  30. Joss
    Joss April 30, 2010 at 3:11 am | | Reply

    No dice on the WP 3.0 beta :( tried a few times but can’t get the rewrites or query vars to work. It keeps giving bad requests, not playing nice with permalink settings :O

    Hope it gets smoother in WP3.0 full release!

    1. Jan Egbert
      Jan Egbert April 30, 2010 at 9:20 am | | Reply

      A quick solution is to reset your permalink settings. Go to Settings > Permalinks and press Save settings. Rewrite rules usually work fine after this trick. Weird, but true.

  31. Piet
    Piet April 30, 2010 at 4:18 am | | Reply

    Hi Justin,

    Thanks so much for your write-up on this subject! It is great to at least be able to understand a bit of all these new functions in the upcoming WordPress version.

    I agree with for example Brad, that for an end-user the dashboard can become much more intuitive with using custom post types; normally it takes quite a bit of effort to let them understand what Posts exactly are, now you can just give them the exact name.

    I have one question, that perhaps you can help me out with. As I am in Europe and (have to) make quite a few projects in multiple languages, how does this work for naming the custom post type? Take for example your “books” suggestion. In other European languages, books obviously is a different word. Is it possible to use get_text calls in naming the custom post type or not?

    Again thanks so much for this tutorial!

    Piet

  32. Bristol solicitor
    Bristol solicitor April 30, 2010 at 8:58 am | | Reply

    This bog is really useful for the word-press user who more ever work over on it. thanks and keep it up …

  33. Xavi Esteve
    Xavi Esteve April 30, 2010 at 9:45 am | | Reply

    Thanks for the guide Justin, that’s exactly what I was looking for!
    BTW, where can I read more documentation on Wordpress 3.0?
    Cheers.

  34. Idealien
    Idealien April 30, 2010 at 10:41 am | | Reply

    Which of the following do you think makes the most sense and a few questions on how to achieve…I am trying to create a custom post type that is “as close to completely idiot proof and self-explanatory” as possible. Using the scenario of creating a custom post type that stores quotes for display throughout the site (sidebars, etc).

    1) Customize the text from ‘Enter Title Here’ to say “Enter Quote Author” so that I can use the title field to generate the quote slug. If I do not use the title field the slug gets generated as ‘auto-draft #’ and you lose the ability to quick edit / trash from the edit menu.

    2) Register a post type with only a meta box (no title, editor) to capture all details (author, quote, author title, etc). What action / hook / filter to connect with to modify the slug generation to match a meta box field? How to specify a column in the edit table view should have the quick edit / edit / trash UI options applied to it?

  35. Brad Thomason
    Brad Thomason April 30, 2010 at 3:36 pm | | Reply

    Hi Justin,

    Great post. One feature I haven’t seen covered anywhere in articles related to custom post types is a listing feature. Do you know if there is an implementation similar to wp_list_pages() or wp_list_categories() that has the power of those functions? Something like wp_list_super_dupers()?

    I’m particularly interested in a function that would list your custom post types, create sublists for children, and echo classes (ie. similar to current-cat, current_page_item, current-cat-parent, etc.) for hierarchical and active relationships in a post or page method (depending on how you enable the custom field).

    If there isn’t one, there desperately needs to be, in my opinion. That would seal the deal.

    1. Brad Thomason
      Brad Thomason April 30, 2010 at 3:44 pm | | Reply

      …or, thinking about it a bit more, a function a bit more broadly applied, like:
      wp_list_custom_post_types()?

  36. Benjamin Cahill
    Benjamin Cahill May 1, 2010 at 2:11 pm | | Reply

    Are there any event plugins that take advantage of custom post types and have a calendar? If not, I may build one.

  37. Sawyer
    Sawyer May 1, 2010 at 5:16 pm | | Reply

    Great and very helpful post. I have my custom post type all set up, however, I was wondering how you get the correct category archive setup for these posts? Right now it’s only displaying posts from the blog.

    1. Ken
      Ken November 5, 2010 at 3:10 pm | | Reply

      They are adding the archive template functionality in 3.1, stay tuned!

  38. Andrew
    Andrew May 1, 2010 at 10:02 pm | | Reply

    Question for Justin or any guru.

    I’ve noticed that creating a just one custom post type adds about 15 new rewrite rules. (18 or 19 if you use CMS Press or Matt’s wrapper for index page archiving –> #comment-188177)

    My question is this. I have a current site, which I’d like to port to wordpress to handle the content, and I can foresee at least 10 – 15 different “custom post types” that I’m going to need to set up.

    15 post types * 19 rules/post type = 285!

    Is that number high? I’m worried about performance. The site currently gets roughly 1000 visitors a day, but peaks at 3k.

    What is an acceptable number of rewrite rules?

    1. Konstantin
      Konstantin May 3, 2010 at 4:41 am | | Reply

      It’ll be fine unless they’re in your .htaccess ;)

  39. WP 3.0 and Custom Post Types May 1, 2010 at 11:44 pm |
  40. Me and My Wordpress
    Me and My Wordpress May 2, 2010 at 9:30 pm | | Reply

    I Not Yet understand with this, but thank you very much for sharing. I’ll come back again to learn this.

  41. Konstantin
    Konstantin May 3, 2010 at 4:41 am | | Reply

    Great post Justin!

  42. Idealien
    Idealien May 5, 2010 at 10:23 am | | Reply

    It’s curious that menu_icon was added to show in the left-hand-menu but something like editwindow_icon which displays the larger 32 pixel version (/wp-admin/images/icons32.png) along with the Add New / Edit [Post Type] Title was not.

    1. Hayden
      Hayden June 3, 2010 at 1:45 pm | | Reply

      @Idealien, I agree. It seems kind of stupid to have the correct menu icon not have the option to create a larger one for the specific pages.

  43. Roberto Costa
    Roberto Costa May 5, 2010 at 11:13 am | | Reply

    Hi Justin,

    I’m relatively new to WP and I’ve been looking for a solution to paginate custom post types for quite a while now with no success yet.
    Your suggestion works to the point of displaying my custom posts list. However, pagination is broken. Using wp-pagenavi, only a box with “Page 1 of 0″ show below the post list which I limited to 2 posts for testing. Using wp default pagination tags, nothing shows below the posts.

    Other relevant details:
    - I placed the query on a page template (see below), created a new page and chose this custom page as the template.
    - This page is not my front page. It’s accessed by a wp_page_list menu item.

    Isn’t it possible to paginate custom post types? I don’t believe so. I prefer to believe it’s my fault. Can someone please help me out of this problem? I’m almost throwing the towel. Thank you in advance.

    My template code:

    <!-- http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress -->
    
     'noticias', 'posts_per_page' => 2 ) ); ?>
    
               		ÚLTIMAS NOTÍCIAS
    
    have_posts() ) : $loop->the_post(); ?>
    
                        <a href="#" title="" rel="nofollow"><img alt="" src="/images/thumb_dalva.jpg" /></a>
    
                            <a href=""></a>
    
                            <a class="continue-lendo" href="" rel="bookmark">Continue lendo</a>
  44. Roberto Costa
    Roberto Costa May 5, 2010 at 11:16 am | | Reply

    Sorry, the code was posted wrongly. How do I post it right?

  45. Donalyza
    Donalyza May 5, 2010 at 9:05 pm | | Reply

    Will this replace custom fields?

    Oh btw Justin, where is your search box in this blog?

  46. Tom
    Tom May 6, 2010 at 10:36 am | | Reply

    Hi Justin,

    Really helpful article to get me started on the WP 3.0 beta but I have one thing which I have been stumped on for a few days! Not sure if it’s something I am doing wrong or if it hasn’t been implemented in the beta yet!

    Working completely I have :
    domain.com/post_type_name/
    domain.com/post_type_name/post_title

    Is it possible to have :
    domain.com/post_type_name/post_type_category/

    This page would list all the custom post types that are within that category. I know I can create a Page for each Category and have a different WP_query on each page, but when this is dynamic and more Categories are added there is a problem!

    Any help is much appreciated!

    Thanks

  47. Jauhari
    Jauhari May 7, 2010 at 8:39 am | | Reply

    Wonderful Tutorial…

  48. Tim
    Tim May 7, 2010 at 11:19 pm | | Reply

    Awesome tutorial. By far the best one I have found regarding custom post types yet.

    I got the custom post type working for the most part and can query them just fine but I am having trouble filtering the posts using permalinks. In the left nav I did a list of the taxonomies to use as navigation but the permalinks arent working. They’re going to the 404.

    I tried changing the slug to what you listed a couple posts up but that broke all of it.

    Here is my code for the custom post type and the taxonomy:

    register_post_type('project', array(
      	'label' => __('Projects'),
      	'singular_label' => __('Project'),
      	'public' => true,
      	'show_ui' => true,
    		'_builtin' => false,
      	'capability_type' => 'post',
      	'hierarchical' => false,
      	'rewrite' => array('slug' => 'projects', 'with_front' => false),
      	'query_var' => false,
      	'supports' => array('title', 'editor', 'author', 'category')
    	));	
    
    	register_taxonomy( 'categories', 'project', array( 'hierarchical' => true, 'label' => __('Project Category'), 'query_var' => true, 'rewrite' => array('slug' => 'projects', 'with_front' => false) ) ); 
  49. Derek
    Derek May 8, 2010 at 12:27 pm | | Reply

    I went ahead and replaced register_post_type() on my wordpress install with your create_my_post_types() function.

  50. Jason Pelker
    Jason Pelker May 10, 2010 at 7:48 am | | Reply

    So many comments!

    This seems like a great plugin to help with creating new custom post types: http://vocecommunications.com/services/web-development/wordpress/plugins/cms-press/

    I found it not too long ago and I don’t know if many people know about it yet. Anyone have a review for it? It does work as advertised, but only an expert would know if it goes about custom post types the right way. I’m curious…

  51. Banago
    Banago May 10, 2010 at 8:55 am | | Reply

    With 3.0 beta2 I have started developing websites with custom content type. I keep coming back to the article – it is such an amazing work putting that together Justin – Thanks very much!

    BTW – It seems I’m the 100th commenter :D

  52. jeff
    jeff May 11, 2010 at 9:47 am | | Reply

    Justin, thank you for this. As always, you’re a great resource.

    One thing that I cannot grasp. When I first heard “custom post types” for WP I was very excited because I envisioned something similar to “Custom Content Types” that Drupal offers.

    The most important feature being the ability to EASILY add custom fields to these content types. So the user who is writing the post would not only see “Title” and “Content” fields for a “Movie” post type, but would also see “Actor” “Director” (etc.) fields where they can easily input the info and it would be displayed in the main body of the page with the content.

    I don’t see how Taxonomy solves this. They are still just tags and do not appear in the main body of the post.

    This is the main reason I must use Drupal for some jobs instead of WP. Some clients need many custom content types (Events, News, Reviews) that need specific fields they can easily fill out and then be displayed.

    I am probably missing something, but adding Custom Fields to a new Custom Post does not seem like an easy task via the control panel…. lots of code customization? I hope I am wrong.

    1. John Myrstad
      John Myrstad May 11, 2010 at 4:23 pm | | Reply

      You may find what you look for in plugins like More Fields, Magic Fields , Verve Meta Boxes and Custom Fields template, once they are updated for 3.0.

      1. shawn
        shawn May 12, 2010 at 2:00 am |

        quick fyi
        Verve Meta Boxes was updated today and works perfectly with 3.0 so far. I am very happy with it.

    2. shawn
      shawn May 12, 2010 at 1:59 am | | Reply

      If by adding ‘actor, and director’ in the admin panel, you mean simply adding in the name of the actor and director, then taxonomies are perfect for that. It’s fairly simple to get the taxonomies related to a given post to show up on a page. Check out Justin’s movie post and you will see it in action exactly as you described.

      Now if you are talking about giving the user the ability to also assign meta data to the actor such as a picture and description as well, then…

      currently I only see 2 possible solutions to this issue, which is exactly what I am working on myself.

      1. taxonomy metadata plugin
      http://wordpress.org/extend/plugins/taxonomy-metadata/

      I have only just begun to play with that plugin, but it looks like it is almost perfect for the job. I only wish the author would have given some clear examples of how to implement it. Right now it’s more for php jockies than regular users.

      2. relational post_types plugin (posts-to-posts)
      http://wordpress.org/extend/plugins/posts-to-posts/

      This one I have actually had a bit of luck with, and can see some serious potential, esp since Scribu wrote it, and he’s the master when it comes to post_types. Give it some time though, as it’s only a few days old.

      Either one, or a combination of the two, should accomplish 95% of everything your mentioning. Especially when Scribu adds the ability to edit one post_type within another post_type admin panel.

      If these don’t fit your needs, check out pods. It does exactly what you are after, and 10x more. For me at least, I prefer for now to stick with native wp functionality, and frankly pods was above my pay grade lol..

  53. angga
    angga May 12, 2010 at 3:03 am | | Reply

    justin, great tutorial

    i’m wp newbie , for this custom type,
    how to make pagination with this custom type
    seems i have wrong permalinks

    i’ve this post-type url (standard slug from register_post_type):
    wp/post-type/post-url

    after click next page, this is the url:
    wp/post-type/page/2
    then redirected to home

    can you help me.

    thanks

  54. David Swain
    David Swain May 13, 2010 at 5:50 pm | | Reply

    Justin

    Is there any way to get a hierachy or the category in the url? i have tried ‘hierarchical’ => true, but nothing changes… have i done something wrong?

    I want something like:

    example.com/images/category-name/custom-post-type-name

    where ‘images’ is the post type.

    Thanks

    David

  55. arkadaslik sitesi
    arkadaslik sitesi May 16, 2010 at 9:14 am | | Reply

    One of the most interesting tutorials I have seen in a while. Thanks a lot

  56. jack
    jack May 16, 2010 at 8:41 pm | | Reply

    how can i copy single.php to single-book.php ,I want to do how to use this page

  57. saqibimran
    saqibimran May 19, 2010 at 10:00 am | | Reply

    This is my first time I have visited here. I found a lot of interesting stuff in your blog.Thanks a lot.

  58. driz
    driz May 20, 2010 at 9:23 am | | Reply

    If you create a type for example called portfolio and your example content might /portfolio/postone/ should you be able to view anything at /portfolio/ like an archive or something or do you have create a page and fake it.

    1. Pedro Augusto
      Pedro Augusto May 21, 2010 at 5:47 pm | | Reply

      Driz, this is exactly what I’m trying to figure out… I tested many possibilities, but without sucess until now. I have 3 post types. I created different template files for each one of them, the content opens perfectly, like /event/staff-meeting. But when I try just /event/ to have a list (loop) of all events of that post type, I’m not getting sucess. Someone knows how to make this possible?

    2. Pedro Augusto
      Pedro Augusto May 21, 2010 at 8:50 pm | | Reply

      Afff… Finally I got an answer to this! Permalink structure for pages is actually what we want. A page called “Event” will have /event as its permalink (since ‘event’ is its slug). What I did was, create a page and call it “Event”. Making use of WP template hierarchy, I created a file and called it page-event.php. And then I placed my post-type query for events in it:

      Not found message goes here…

      <?php the_title();

      Does someone have a better idea? Suggestion?

      Thanks for this excellent post Justin!

    3. Pedro Augusto
      Pedro Augusto May 21, 2010 at 9:01 pm | | Reply

      Trying the code again…

      `

      Not found message goes here

      `

    4. Transporter78
      Transporter78 June 9, 2011 at 4:10 am | | Reply

      dont know if its new, but you can simply copy your existing category.php/archive.php file and rename it to archive-{posttype}.php. Now /portfolio/ works as an archive of custom posts.

  59. Marcus Paris
    Marcus Paris May 20, 2010 at 3:23 pm | | Reply

    Honestly… you’re a genius. I’m in the process of building my first web site (wordpress platform) and this info is priceless. I think I will print the page to have it close by. Thanks for the info. I’ve bookmarked your site and I will surely return.

  60. Pedro Augusto
    Pedro Augusto May 21, 2010 at 9:03 pm | | Reply

    I’m sorry… how can I show the php code on this comment form?

  61. Drew
    Drew May 23, 2010 at 3:36 pm | | Reply

    Instant bookmark… gonna be needing this in the next few months for sure!

    Thanks for taking the time to go through all of these features.

  62. pmdci
    pmdci May 25, 2010 at 3:16 am | | Reply

    I think there is a but in WP 3.0 b2 when using the is_post_type() function…

    I tried adding the following code in my sidebar:

    if ( is_single() && is_post_type(‘post’,$post_id) ) { include ‘datasheet.php’; } ?>

    So the idea is that when viewing SINGLE pages and only of the type POST (the default post type), it would then include the datasheet.php

    However, it happens that datasheet.php is being included when viewing ANY post type. Besides the default post type, I have 3 others. The datasheet.php appears when viewing any of those posts.

    Now for something curious: If I type for my post type name something that doesn’t exist, say:

    if ( is_single() && is_post_type(‘garblegarblegarble’,$post_id) ) { include ‘datasheet.php’; } ?>

    Then the datasheet.php is NEVER included when viewing a post…

    Probably a bug, right?

    I posted about it on the forums: http://wordpress.org/support/topic/402823

    Regards,
    P.

  63. Summer
    Summer May 25, 2010 at 9:41 am | | Reply

    This is an excellent post for us wordpress bloggers. Lots of useful information, thank you for posting it.

  64. Håvard Pedersen
    Håvard Pedersen May 26, 2010 at 12:54 pm | | Reply

    This is just awesome! I have several ideas already for what to do with this. :) But is there any way to attach per-user metadata to custom post types, like a rating or an event attendance status?

  65. Meesan | Gaming Computers Canada

    Great guide! I’ve learned a ton off of all these little tips! Thanks for the great advice! Absolutely incredible info. Thanks again!

  66. yeswework
    yeswework May 28, 2010 at 5:35 am | | Reply

    Hi Justin,

    along with almost everyone else, we’re really looking forward to custom post types in WP, but we’ve got some niggling doubts about the implementation, or about how various WP blogs are suggesting post types be implemented. Primarily, isn’t functions.php the worst place to set up post types, since register_post_types also affects the GUI of wp-admin – which is never usually theme-related? If one sets up post types within a theme-specific file that also happens to be subject to fairly frequent changes and improvements during build and once a site is live, aren’t there several big risks? Namely:

    1) you could register a new custom post_type, start inserting posts, and then (you, a co-worker, a hacker, an ftp error) could willingly or inadvertently change functions.php and change the definition of the post_type (which, being a theme file not core wp-admin, wouldn’t run checks/validation of the definition against the database) leaving all the posts already entered either orphaned or broken, and the database cluttered with irretrievable junk.

    2) your register_post_type function will get called at every page load: isn’t that wasteful at best, risky at worst?

    3) you (or your client) could switch theme and, in doing so, lose the custom post_types – not just their display, but their admin too. It’s one thing to need to re-jig a theme to display them properly, but surely quite another to have to redefine their structure?

    Although you mention in the article that register_post_types could be called from a plug-in, this also seems contradictory for such a deep-rooted new feature: we can imagine lots of competing plug-ins emerging, some with checks and balances, some without; some with neat admin GUIs, some without. Maybe that’s a benefit – natural selection will ensure the best plug-in emerges eventually – but in the meantime, WP support risks being flooded with desperate cries for help.

    People often mention drupal and the CCK module… the point with that seems to be that the development path happened the other way round to WP and custom post types: CCK was developed (and evolved) as an external module for adding custom node types. It was only taken into drupal core once it (and its administration and security models?) were judged mature, stable and useful enough. With WP, what appears to be happening is the opposite: a core feature is added, but apparently without a good wp-admin section or data security features, and its implementation is being left up to non-core plug-in developers and, even worse, themers like me.

    Doesn’t this risk making implementation of the new custom post types feature patchy and buggy, reducing WP’s perceived simplicity and strength? Custom post types seem to us to be so important that their registration and management should be in core wp-admin just as most of the best new features of recent releases have been.

    Our understanding of the way post_types will work may be flawed or incomplete, in which case we’d LOVE to be reassured/corrected, because we really can’t wait to use them and feel that they’ll make WP an even stronger system for even more flexible sites. But we’re a bit worried at the moment.

    Any comments?

  67. Efe
    Efe May 30, 2010 at 5:43 am | | Reply

    I have been looking around the database and found that custom post types are implemented very cleverly. First of all, it is not really going deep rooted, its just an attribute in wp_posts table, all the magic is done on php level and everything is based on (imho) already perfectly working post/page post types. I believe they have been already making code level changes for custom post type to be possible for a long time (like unifying the editor page for posts and pages).

    My 2Cs;

    1-) functions.php is one of the right places to make the registration, custom post types can be seen as a feature of the theme.
    2-) all logic regarding finding and displaying custom posts created when the theme is loaded. Therefore WP_Query and co is aware of the new custom post type after register_post_type() has run. There is no database query to ‘discover’ their presence. I find this effective, fast and flexible.

    So, I think there is no need to worry,
    Cheers

  68. Ilia
    Ilia May 30, 2010 at 1:06 pm | | Reply

    The major functionality I was waiting from WP 3.0 was Custom Post types. But I still don’t see how to determine exact custom fields for custom type.
    I mean: we create movies database and create custom field “Actor”. Is there a way to only show this custom field when editing custom post type “Movies”? Because when I create a usual post I see “Actor” in custom fields and so on…

  69. Renee
    Renee May 31, 2010 at 1:53 am | | Reply

    Curious about how to do certain things:
    * Create an archives page (both a list and a search result page).
    * Create sidebar navigation that lists “categories” and recent “posts” from custom post types.
    I wanted to create a section on my site that would allow me to post different articles, and while I can do work-arounds for some things, I’d rather have a cleaner, easier, and much more organized way of doing things before I implement some of my ideas.
    Any way I can achieve those things without to edit a thousand files or create an additional plugin to use?

  70. Richard Sweeney
    Richard Sweeney June 2, 2010 at 3:48 am | | Reply

    Great post! Many thanks for this, you’ve cleared up a load of questions I’ve had!

    One thing I can’t seem to be able to do is to perform a query from a custom post type within a specific category:

    'movies', 'category_name'=>'actors' );
    $the_query = new WP_Query($args);
    $the_query->the_post(); the_content();
    ?>

    I can display the results of the query ok without the category_name, but once I add that it doesn’t display anything!

    Any thoughts?

  71. Hayden
    Hayden June 3, 2010 at 1:53 pm | | Reply

    This was a good article and proceeds with a good discussion. I am fairly new to PHP programming. I’ve created a custom post type fine and added some meta boxes. I have some questions with regards to creating a meta box for uploading images.

    My custom post type is “Case Studies” which I have the editor registered to show a description for what the project was about. I have a custom meta box for showing the “Services Provided” (which is just a check box group). The final thing I want to be able to do is create some sort of image uploader. For each “Case Study” I want to display images. I would like to use some javascript on the presentation part to display these images.

    Magic Forms was mentioned earlier about easily adding images but I want to stay away from using plugins if at all possible.

    Do you have any suggestions or could you point me in the right direction? Thanks!

  72. Tim Nicholson
    Tim Nicholson June 4, 2010 at 12:25 pm | | Reply

    Justin,

    I have really been thinking about custom post types as a great way to have a simple forum that uses the standard WP database tables. I even started hacking some stuff in WP2.9, but decided to wait for 3.0. So I’m VERY interested in your work on a forum “plugin”. Your screenshot you posted looks absolutely perfect as I was thinking of modeling the look and feel like bbPress as well.

    Since it sounds like you are looking for suggestions, I have a couple of key suggestions that wouldn’t naturally be available with just the WP3.0 custom post types:

    1) I would like to a *separate* RSS feed for forum posts. Every discussion forum in the world has this, but this isn’t standard functionality with custom post types. In fact, it appears custom post types were designed to be used more like custom *pages* in that they get a permalink and it can be specified that they are searchable, but they do not appear in any RSS feed format.

    2) Having run various forums over the years, it seems that most website owners would like to be able to easily specify that their “news” (“blog”) type posts get placed into the forums. Historically, people are more willing to comment on a forum than on an actual “news” article. At least that has been my experience with hobbyist type sites. I know this isn’t a problem for Engadget or CNN, but I think for smaller websites it could help increase the number of comments.

    But if the forums are custom post types, then I don’t believe that we can simply flag a “blog” post to appear there, right? This would be easier if the forums were simply blog posts (and their comments) within a standard category taxonomy. i.e. I flag the article in its normal category and also tick off what forum category it should appear in. Notice no duplication of data and comments on the forums will appear on the blog article as well.

    So with the combination of these two requirements (RSS feed and ability to post to the “blog” and “forums” at the same time), would it be better to have forums that are just normal blog posts and use the built-in category taxonomy or create a custom “forum” taxonomy? With that method, you’d have to filter your main RSS feed to exclude the posts that are *only* in the forum (but show them in the “forum” RSS feed). With custom post types you’d have to build your own RSS feed for the forums (I assume) and that sounds harder than simply hiding some posts from the main RSS feed.

    What do you think?

  73. Lars Farstad
    Lars Farstad June 4, 2010 at 9:06 pm | | Reply

    Hi Justin, firstly thanks for the article and all the other awesome stuff you do.

    I’ve been trying to figure out the best way to create a relationship between two or more custom post types but haven’t really been able to come up with a good and practical way of creating a direct relationship either as a 1-n or n-n relationship.

    I’ve got the following custom post types:
    - Merchants
    - Special Offers
    - Brands

    Merchants can have multiple special offers however a special offer can only have on merchant.

    Brands can be associated with multiple merchants and a merchant can sell multiple brands. Brands may sometimes be associated with special offers and a special offer may apply to multiple brands.

    So far the solutions I’ve come up with seem to require having duplicate entries for entities e.g. merchants as both a taxonomy or custom field and as a custom post type.

    So far the solution I’ve come up with involves create a custom taxonomy containing merchant names, add that custom taxonomy to both the merchant custom post type and any other custom post type that needs to be associated with that merchant.

    Is there a better way of doing this? E.g. the ability to load the titles of all posts within a single custom post type into a dropdown select box or list of checkboxes in the create interface for another custom post type?

    I just want to make sure that there isn’t a cleaner, more direct or more obvious way of doing this that I’m not seeing before I commit to the custom taxonomy solution.

    1. Markgt
      Markgt June 7, 2010 at 7:09 am | | Reply

      Lars, I’ve got the same problem – associating custom posts types…

      I’ve got DESTINATIONS and TOURS, and have struggled to find an easy way to link the two (both ways), apart from creating custom taxonomies of the same (Destinations and Tours)… and then it starts getting messy – especially if a client has to add a new post AND taxonomy for a new tour…

      Yes! is there any way to load a list of all posts within a custom posts type?

      Has anybody got any ideas? please!

  74. Christian Engineers in Development June 5, 2010 at 11:57 am |
  75. od3n
    od3n June 6, 2010 at 9:17 am | | Reply

    why does my custom taxonomies (categories and tags) shown up in custom post list?

    how to get it works?

  76. Nique de Graaff
    Nique de Graaff June 6, 2010 at 5:27 pm | | Reply

    Is it possible to use a slug like this?

    http://www.mallona.nl/webspots/91230/crash-near-schiphol-amsterdam/

    How to add the ID at the slug level. I want this, so the slug-title does not matter anymore. Searching on ID is much faster to get more peformance out of wordpress.

  77. Ovidiu
    Ovidiu June 8, 2010 at 6:17 am | | Reply

    wondering about your remarks above about the single.php and this text: If you’re using a smart theme like Hybrid, this template will be super_duper.php.

    As I am using hybrid 0.8.1 and there is no single.php only a singular.php I am unsure on which template to base my recipe.php for my new custom post type called “recipe”

  78. Joe Dominican
    Joe Dominican June 8, 2010 at 7:43 pm | | Reply

    Is there a better way of doing this? E.g. the ability to load the titles of all posts within a single custom post type into a dropdown select box or list of checkboxes in the create interface for another custom post type?

  79. Rick Adlam
    Rick Adlam June 9, 2010 at 6:22 pm | | Reply

    Great post Justin. I somehow found your old post about custom posts on WP 2.8 and left a comment there http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28#comment-200736

    This comment asked how I could use custom posts in Wp 3.0 when released for a mortgage comparison site I am planning.
    Here is the question and the variations possible for a home loan in Australia.

    “How would I best use custom posts and taxonomies on this site? [Why did you elect to go for non hierarchal taxonomies.]
    Most people only focus on interest rates.
    Loans however could be classified by, Funder, loan size, down payment, lender, lender type, distribution channel/s, loan type, client type/ employment stability, income and job type/ partners/ downpayment, mortgage insurance [variable on deposit amount] loan purpose, loan costs, Property security, loan size, Interest fixed or variable or combo/ revolving credit line, Repayment options, Loan style, Loan options, Interest rates, Introductory discount offers, Loan terms, Loan conditions, Early repayment options, application fees, establishment fees, ongoing fees and charges, deferred fees, early repayment penalties, default fees and interest rates, default processes, Loan documention type, Credit rating/history/ scores. etc.
    E.g. Client type could be first home buyer, self employed, with less than two years income/tax statements, with minor credit defaults. In Australia he would be paying a higher interest rate than a professional, such as an employed lawyer on $150,000 with clear credit, and be precluded from applying with many lender types [and or loan types]. Incomes, dependents and financial commitments can also affect the loan offered.
    Each one of these can have a multiple choices, and or be dependent on other areas.”
    Any suggestions would be appreciated.

  80. SHW
    SHW June 12, 2010 at 12:29 pm | | Reply

    Thanks a lot for this great explained article!

    If got a question though: Do you know, how I can get the CPT queried by the searchform? Unfortunatelly I seem to fail with everything I try.

    Best wishes,

    Steffen

  81. Markus
    Markus June 13, 2010 at 3:52 am | | Reply

    funny 404 bug :p

  82. Gavin
    Gavin June 13, 2010 at 1:38 pm | | Reply

    How do I get the custom post type of the post to show up in the loop? I’ve created a few custom types, and I’d like the type to appear in a dialogue balloon over the thumbnail, so that visitors know they’re getting for example, a Video or a Photo. Cheers!

  83. Seth Shoultes
    Seth Shoultes June 16, 2010 at 12:43 am | | Reply

    My hat is off to you Justin. This is one heck of a detailed tutorial :)

    One of the custom post types I can see myself making is an event listing/information post type. I made a plugin called Advanced Events Registration (http://shoultes.net/wordpress-events-registration-with-paypal-ipn/) for WordPress that allows blog owners to publish events (including registration forms) to their blog. I also offer a free version, but the pro version of the plugin is actually a full event management suite which also allows you to create a post at the time of event creation. At the moment the new post is created by including a “post template” and a little bit of ob_start() and ob_end_clean() magic.

    I am going to see if I can integrate what you have posted here. This looks like it may be a very promising alternative to what I am currently doing with ob_start() and ob_end_clean().

    Thanks!

    Seth Shoultes

  84. The Frosty
    The Frosty June 16, 2010 at 3:38 pm | | Reply

    Wondering if anyone has attempted to import current blog XML or RSS feed into a custom post type, is that possible yet?

  85. Michael Wellspear
    Michael Wellspear June 16, 2010 at 8:26 pm | | Reply

    Amazing post! Thanks alot!

  86. lukeMV
    lukeMV June 17, 2010 at 2:22 pm | | Reply

    Any easy to understand guides on how to add options to the custom posts? For example, if a movie is drama, comedy, horror…. to have those options as check boxes WITHIN the custom post edit panel? I can’t seem to find a guide or plug-in for that.

    1. Gina
      Gina June 21, 2010 at 3:46 pm | | Reply

      I would like to know too…

  87. Arvind
    Arvind June 19, 2010 at 9:17 am | | Reply

    thank you for your post. this is great for me. specially for those who are new to custom post type. thanks again.

  88. wawan
    wawan June 19, 2010 at 1:36 pm | | Reply

    wow….. nice posting.. thanks for share.

  89. Kevin Tan
    Kevin Tan June 23, 2010 at 4:14 pm | | Reply

    Great post Justin. It’s always good to spice up your blog to separate yourself from the rest of the flock.

  90. mezar işleri
    mezar işleri June 24, 2010 at 7:36 am | | Reply

    It is a good idea to plot the data so that you can explore its features.
    An exploratory plot of your data enables you to identify discontinuities
    and potential outliers, as well as the regions of interest.
    Thanks…

  91. Jake Goldman
    Jake Goldman June 27, 2010 at 6:41 pm | | Reply

    For those of you asking about / lamenting the lack of custom post type “archives” support (an equivalent to the blog home for a custom post type), I’ve put together a plug-in that plugs that hole in 3.0.

    http://www.cmurrayconsulting.com/software/wordpress-custom-post-type-archives/

  92. Richard
    Richard June 28, 2010 at 12:37 pm | | Reply

    I’d be very grateful if you could add a few lines to your tutorial showing how to create a new role and give it the custom post type capabilities. Try as I might I can’t get it to work. In fact, including the capability_type argument WITHOUT a role ‘breaks’ the admin page, simply showing tags.

    A role is definitely needed to make the capability_type argument work.

  93. Borneo Ngeblog
    Borneo Ngeblog June 29, 2010 at 10:45 am | | Reply

    Nice Article,,, Thanks You

  94. Loren
    Loren June 30, 2010 at 12:49 pm | | Reply

    Hi Justin,
    I am using the “Content Permissions” component of your “Members” plugin and cannot seem to figure out how to add that feature to a Custom Post Type. How would I do that?
    Thanks!
    Loren

  95. Alireza
    Alireza July 1, 2010 at 3:51 pm | | Reply

    i created two post-type (ex. movies and gallery) ,but i need a monthly archive for gallery and monthly archive dont work in gallery, please help me to create a monthly archive for post-type.please!

  96. Benjamin Knight
    Benjamin Knight July 6, 2010 at 12:00 am | | Reply

    In the page attributes box I see no dropdown for specifying a custom page template for my custom post type. Am I doing something wrong? I have hierarchical set to true.

  97. Jordan
    Jordan July 6, 2010 at 8:25 pm | | Reply

    Hey Justin,

    Thanks for the guide. I am having on issue. When I create a custom post type and use it in a category, it does not show up under “yoursite.com/categoryname/”

    How would I go about doing this?

    Thanks, Jordan.

  98. Reading List: July 8th July 8, 2010 at 3:31 am |
  99. Lee Peterson
    Lee Peterson July 9, 2010 at 1:01 pm | | Reply

    Justin,

    How would a conditional statement work with a custom post type in this scenario:

    I have a Staff page with individual Staff Members.

    On the individual Staff Members’ page, I’d like to display a list of their qualifications (via taxonomies) in the sidebar.

    So, in my sidebar.php, I’d like a conditional statement that says “if this is an individual staff members’ page, then display a block listing their qualifications”.

    My roadblock is deciding whether I should be using [code]is_single('staff_member')[/code] or something else. Upon creating the custom post type, the body class returns ‘single-staff’.

    Any thoughts? Let me know if I’ve been too vague or left out important info here.

    Much appreciated!!

    1. Lee Peterson
      Lee Peterson July 9, 2010 at 3:33 pm | | Reply

      Well, that took some thinking through, but I figured out why I couldn’t get this sidebar block to show up.

      First, I needed to scroll down in the WP Codex a bit more to find is_singular and how it mentions [blockquote]True when viewing a post of the Custom Post Types book. Introduced with Version 3.0.[/blockquote]

      Then it was just a matter of making sure my other conditional statements above it that use is_single weren’t conflicting. :-)

      Doubt anyone cares, but there it is.

  100. Kadrwa
    Kadrwa July 9, 2010 at 1:31 pm | | Reply

    I am using this for product display. My products have sub categories like Main Category -> Sub Category. Do I need to install custom post type for every sub category?

  101. Alex Buri
    Alex Buri July 13, 2010 at 3:23 am | | Reply

    Just wanted to say thanks for a clear and easy-to-follow explanation of how to use custom posts. It’s rare for a beginner like me to be able to follow someone else’s instructions without misunderstanding.

  102. Toni L
    Toni L July 13, 2010 at 8:28 am | | Reply

    Hi Justin,

    Have you figured out how to use sticky posts with custom posts? Would love to know.

    1. bineet chaubey
      bineet chaubey December 30, 2010 at 3:24 am | | Reply

      hi i have also face same problem . how we can add sticky post featured in our custom post type. please help me . i am making a project , in which sticky post featured is essential in custom post type ” review “. please help me

  103. Gary Cao
    Gary Cao July 14, 2010 at 2:35 am | | Reply

    For those who are having 404 error with custom post type, simply flushing the rewrite table upon activation sometimes doesn’t work. You have to first register the post type then flush the rewrite table in the activation hook.

    function my_register_post_type() {
    // code to register your custom post type
    }
    
    register_activation_hook( __FILE__, 'my_activation_hook' );
    
    function my_activation_hook() {
        my_register_post_type(); // this has to happen first before flushing the rewrite rules
        flush_rewrite_rules( false ); // soft flush is enough
    }
    1. Andrew Bailey
      Andrew Bailey December 8, 2011 at 9:59 am | | Reply

      +1 Gary!

      this was making me go bonkers!!

      I had the rewrite in the activation but it wasn’t working so I moved it to after the register_post_type and that worked but I seem to recall that the flush_rewrite_rules is pretty intensive and having it run every time the register function ran seemed silly.

      having the register_post_type function run before doing the flush_rewrite_rules in my activation function did the job.

      thanks! maybe now I can get some real work done! haha

  104. Rem
    Rem July 15, 2010 at 2:22 am | | Reply

    Im having trouble here – Showing multiple posts from our custom post type

    Using query, I can show up to 10 posts on page. But what about the pagination?

    ie, I have custom post type called “Services”, I have 20+ services.

    So specific service url is site.com/services/service-name01
    Ten services will show on site.com/services (I’ve put that code in services.php and used it as page theme by creating a page called services)
    Now I want to show rest of services on site.com/services/page/2 Any way?

    1. Gabriel Izaias
      Gabriel Izaias July 15, 2010 at 9:20 am | | Reply

      @Rem, you can use this to solve the pagination issue:

       'post',
                'paged'=>$paged,
           );
           query_posts($args);
      ?>

      I hope it helps you.

      1. Gabriel Izaias
        Gabriel Izaias July 15, 2010 at 9:24 am |

        Something went wrong with my comment. Probably because I used .
        Let’s try without it:

         'post',
        	'paged'=>$paged,
            );
            query_posts($args);
        ?>
  105. Mário
    Mário July 15, 2010 at 11:29 am | | Reply

    A question to Otto, about PODs vs. Custom Post Types.

    If we include the post types in the functions theme, then this will be inherited to the network sites. This means that if I want to have a site where everybody can create their own Super Dupers listings, then all I have to do is make available themes that have that custom post type.

    How does this work with POD? Can I make every user in the network use that post type?

  106. Branden Silva
    Branden Silva July 18, 2010 at 8:54 pm | | Reply

    Justin do you think you could write up a post on how to properly implement your custom post types to display the data with the title? So a Podcast would have length and speaker listed as categories and those options, when checked, would be displayed within the top view of the Podcasts in wordpress.

    I know its fairly simple but it may be helpful and compliments your above code.

  107. Kathyp
    Kathyp July 19, 2010 at 1:05 pm | | Reply

    Maybe its because I’m new to Wordpress but that 404 trick was news to me and has just fixed my custom post type stuff after scratching my head all day. Thank you.

  108. Faye
    Faye July 22, 2010 at 10:49 am | | Reply

    Wonder if you could shed your expert light on this one…I’ve created a hierarchical custom post type called Events, with the intention that any given event (eg Acme Conference 2010) will have several child posts (eg Agenda, Location, Bookings etc).

    However, I can’t work out how to output a list of all the child posts of Acme Conference 2010. The WordPress Codex suggests that they’ve ‘added custom hierarchical post type support to get_pages() ‘, but has anyone had any success in listing out child posts from a hierarchical custom post type?

  109. Jason Kadlec
    Jason Kadlec July 26, 2010 at 6:46 pm | | Reply

    Any update on the tutorial on Custom Post types with Taxonomies?

    Maybe I should just go back to the More Fields plugin, but it’s so buggy in 3.0!

    I want to be able to get the posts from my Custom Post type, and then filter those posts by a custom Taxonomy.

    I’ve seen the debate on Otto’s site and the fact is, my client needs a custom UI to data enter. the_title() and the_content() and custom fields are not going to cut it.

    I’ve been using the “more fields” plugin but it’s sooo buggy. Also, I want these custom posts to be always separate from the blog posts. The site has a blog and these posts are not blog posts.

    I can’t believe WordPress can’t handle both queries – one to the custom posts and then by the taxonomy.

    I’ve tried this:

    'XYZ',
      'post_type' => 'Custom',
      'post_status' => 'publish',
      'posts_per_page' => -1
    );

    All the posts from the type “Custom” are pulled, regardless of their being in Custom_Taxonomy XYZ or not.

    What I *really* want is to be able to dynamically set the value of the Custom Taxonomy.

    I do this with posts by matching the category name to the post title:

    query_posts('category_name='.get_the_title().'&post_status=publish,future'.'&posts_per_page=10'); 

    Any chance something similar can be done with Custom Post Type + Custom Taxonomy?

    1. Markgt
      Markgt July 27, 2010 at 3:05 am | | Reply

      Jason, ive had the same problem, and was surprised that Wordpress couldn’t handle it natively.

      I came across the Query Multiple Taxonomies plugin (http://wordpress.org/extend/plugins/query-multiple-taxonomies/).

      so you could have http://www.sitename/custom_post_type/?some_taxonomy=some_value...

      BUT if you had another custom post type with linked to the same taxonomy THEY would show up as well. I managed to get around this by, on the custom post type template (eg: product.php), to only display posts of a certain custom post type:

      // display your content
      ….

      AND MORE importantly, i found that custom post types created by More Fields (or More Types) for some reason can’t handle the custom query. To get around this i used Custom Post Type UI (http://wordpress.org/extend/plugins/custom-post-type-ui/) to create the custom post types.

      Hope this helps somehow. ( Unfortunately i cant paste the code as its for a client. )

  110. Markgt
    Markgt July 27, 2010 at 3:10 am | | Reply

    Arg, the code didnt show up… trying without php tags

    //start the loop here ....
    $isposttype = get_post_type();
    if ($isposttype == 'accommodation')
    // display your content here
  111. Justin Tadlock — Jan Boddez July 27, 2010 at 3:54 pm |
  112. Daniel
    Daniel July 27, 2010 at 7:42 pm | | Reply

    I can’t believe that I only just came across this post. This is exactly the kind of thing that would have just cut my custom post type learning curve in half! Thanks anyway for creating a great resource…

  113. Chris
    Chris July 28, 2010 at 4:03 am | | Reply

    Hi,

    I was just wondering if it possible for text area fileds in custom post types to be converted to wysiwyg text editors?

  114. Shaun
    Shaun August 2, 2010 at 3:58 pm | | Reply

    “One thing I would warn against is trying to separate your blog posts in this way. You have categories, tags, and custom taxonomies at your disposal if you’re just looking for a way to label them.”

    Justin – Can you elaborate on what you mean by this? Are referring to styling your posts different as something to stay away from with custom post types, and using your existing category, tag taxonomies instead to do so?

  115. lorenzo
    lorenzo August 9, 2010 at 9:11 pm | | Reply

    hi Justin, this is quite useful thanks!
    one question which i could not find elsewhere: if custom post types are making wordpress more like a cms and different tamplates can be aplied to different posts, is it possible to have more than one ‘editor’ box which is then rendered in particular divs in the actual theme? (i.e. more like a template skeleton, with editing boxes as a way to edit the content only in particualr sections)

  116. Wills Bithrey
    Wills Bithrey August 14, 2010 at 1:36 pm | | Reply

    Hi Justin,

    Great Tutorial :) , Just one small issue, I was getting stuck using the is_post_type() function with an error like this: “Call to undefined function is_post_type() in …” on the release version of WP3, and after some searching found that it has been renamed to “post_type_exists()” – Just a heads up to others who might be suffering the same fate :) .

    1. Ben
      Ben August 16, 2010 at 3:58 am | | Reply

      Yep, I’m suffering the same fate… ;)

      And still do so, because I want to check at my single.php which one of my 3 Custom Post Types is showing. post_type_exists('custom1') is always true since the “custom1″-Post Type exists.

      Any ideas?

      1. Ben
        Ben August 16, 2010 at 4:03 am |

        Viewing my Cheat Sheet, the solution is quite obvious…

        In the loop:

        if $post->post_type == 'custom1'

        That’s it. :)

      2. paul
        paul August 17, 2010 at 10:42 am |

        thanks Ben, I was doing something more verbous, so that helped!

      3. Jason Kadlec
        Jason Kadlec September 14, 2010 at 4:00 pm |

        That’s hot. Thanks Ben!

  117. JB
    JB August 16, 2010 at 4:17 pm | | Reply

    Thank you very much for putting all theses information together ! Just a question, can we have template and custom field for taxonomy ? Lets say I have a custom post type ‘MOVIE’ and I want to create a custom taxonomy ‘ACTOR’, can I put custom field to actor, like name, photo, year of birth,….

    Or should I create two custom post type and somehow linked them ?

    Thank you for helping

  118. Jason F
    Jason F August 19, 2010 at 11:20 pm | | Reply

    I’m really looking forward to the tutorial on combining custom posts and taxonomies, like it appears you did in your movie and book review demos. I just can’t seem to find a good source that explains this.

  119. Jason Kadlec
    Jason Kadlec August 24, 2010 at 3:01 pm | | Reply

    I’ve got some permalink issues….visiting the permalink page to refresh the rules will either make page.php work correctly but cause single.php to fail.

    If I set things back to default, and then click from WordPress admin to view a post, then a page, then a custom post type, they will all work.

    Now if I change permalink settings back to year/month/postname (using the % of course) — everything works again.

    Until I add a post to one of my custom post types. Then it all breaks again.

    Any ideas on what could be going wrong? It’s so odd that I can get either single.php OR page.php to while my custom post type is working (single-custompost.php ) but not both.

    Thanks!

    1. Jason Kadlec
      Jason Kadlec September 14, 2010 at 4:01 pm | | Reply

      SOLVED. I was using a custom taxonomy named ‘year’. That’s a reserved term it seems so it was messing things up.

      Changed the custom taxonomy to a different name and all is well. (except the hours spent figuring that out!).

  120. techjacker
    techjacker August 27, 2010 at 6:24 pm | | Reply

    How do you avoid the rewrite slug page giving a 404??

    ie: 'rewrite' => array('slug' => 'upcoming-events', 'with_front' => true),

    this URL works: blog.com/upcoming-events/post-xyz
    this URL returns a 404: blog.com/upcoming-events/

    I’ve searched everywhere but can’t find any documentation on this

  121. Jordan
    Jordan August 28, 2010 at 12:15 pm | | Reply

    Is it possible to use plugins like All in One SEO or WP -> Twitter with custom post types?

  122. Huw Tyler
    Huw Tyler September 2, 2010 at 7:22 am | | Reply

    THANKS SO MUCH FOR THE LITTLE PART ABOUT THE 404s! Spent hours checking through code trying to find out why it just wouldn’t work! simple when you know how… thanks!

  123. Aldi
    Aldi September 5, 2010 at 3:33 pm | | Reply

    Could anyone tell me how I could retrieve a post-type’s label (plural name) by using the post-type’s name/slug?

    Thanks!

  124. Jeffrey Lin
    Jeffrey Lin September 6, 2010 at 8:21 am | | Reply

    thanks Justin AGAIN! We built so many features based on first your custom taxonomies tutorials and now custom post type.

    first test of custom post type with our (incomplete) stock market dictionary: http://marketheist.com/definition

  125. kevin
    kevin September 17, 2010 at 5:27 pm | | Reply

    Dude awesome post, a huge help0 and so much new possibilities now with the custom post types and custom taxonomies.

    Thanks a lot.

    ps: i want the book you’ll write!

  126. Custom Post Types | poetry4me.com September 18, 2010 at 12:01 pm |
  127. Andrew Carter
    Andrew Carter September 22, 2010 at 5:08 pm | | Reply

    I really like custom post types, as it makes it way easier for clients to understand what’s happening (opposed to using custom fields!). I had a lot of trouble getting the “tags.php” page to work after getting custom post types up and running but found a fix. http://andrewroycarter.com/wordpress-2/wordpress-custom-post-types-tags-not-working/ It’s more of a workaround, so I’m really interested to see if there’s a better solution…

  128. Janvier
    Janvier September 22, 2010 at 8:39 pm | | Reply

    Awesome Post. I finally got “super dupers” working as videos for my site!

    Thanks for the amazing work

  129. James Weaver
    James Weaver September 23, 2010 at 2:58 pm | | Reply

    Thanks for the post, I’ll have to try this out on my themes!

    Thanks Again,
    James

  130. Toure
    Toure September 28, 2010 at 10:00 am | | Reply

    Great post, I will be using this for a small project. thanks.
    But does anyone has an idea about repeating events

  131. Popovici
    Popovici September 29, 2010 at 2:00 am | | Reply

    Hi, I’ve been using your tutorial to create a “job” post type but I got a strange error when I added this line to functions.php:

    add_action( 'init', 'create_my_post_types' );

    The error was “fatal error call to undefined function “add_action”

    Even more wierdly is that, when I took that line out, the error dissapeared, but of course no function was registered.

    Got an idea? Thanks a lot!

  132. Gumz
    Gumz October 10, 2010 at 10:12 am | | Reply

    Hi Justin,

    Thank you very much for the information, it gives me additional knowledge of using the custom post type. I’m glad to be able to search this post. Very detailed :)

  133. Custom post types in WordPress | catz October 15, 2010 at 8:43 am |
  134. Leo
    Leo October 22, 2010 at 12:01 pm | | Reply

    Thanks for the info Justin. But I have one question.

    When adding new meta boxes with custom fields for a custom_post_type they show up in the regular Post pages as custom fields already selected.

    Is there anyway to prevent that from happening?

    Thanks!

  135. darrinb
    darrinb October 29, 2010 at 9:51 am | | Reply

    A small detail I noticed is that even though you can set a custom icon for your Custom Post Type to display in the sidebar menu, the default “thumbtack” icon displays when you navigate to the post edit page or the post listing page.

    Like I said, a small detail, but I’m a sucker for consistency. Anyone know of a way to address this?