First Impressions of Custom Post Type

One of the new very interesting things in WordPress 3.0 are individual post-types you can implement with little effort. Back then, you had to expand the database and write your own interface for it, now you just have to add a few lines of code – of course this is just the current state, which can be change until the final release.

After Justin had been playing with these types, we check out the possibilities of types for “Movies”.

Simple Solution

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

default custom post type

More parameters for meta-boxes

Of course there are a number of parameters for this function and so the behavior and appearance of the corresponding edit page can be controlled quite easily, a small sample with additional meta boxes:

function post_type_movies() {
	register_post_type(
                     'movies', 
                     array('label' => __('Movies'), 
                             'public' => true, 
                             'show_ui' => true,
                             'supports' => array(
                                        'post-thumbnails',
                                        'excerpts',
                                        'trackbacks',
                                        'custom-fields',
                                        'comments',
                                        'revisions')
                                ) 
                      );
	register_taxonomy_for_object_type('post_tag', 'movies');
}
add_action('init', 'post_type_movies');

The default arguments

// Args prefixed with an underscore are reserved for internal use.
$defaults = array(
    'label' => false,
    'publicly_queryable' => null,
    'exclude_from_search' => null,
    '_builtin' => false,
    '_edit_link' => 'post.php?post=%d',
    'capability_type' => 'post',
    'hierarchical' => false,
    'public' => false,
    'rewrite' => true,
    'query_var' => true,
    'supports' => array(),
    'register_meta_box_cb' => null,
    'taxonomies' => array(),
    'show_ui' => null
);
  • label – A descriptive name for the post type marked for translation. Defaults to $post_type
  • public – Whether posts of this type should be shown in the admin UI. Defaults to false
  • exclude_from_search – Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public
  • publicly_queryable – Whether post_type queries can be performed from the front page. Defaults to whatever public is set as
  • show_ui – Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public
  • inherit_type – The post type from which to inherit the edit link and capability type. Defaults to none
  • capability_type – The post type to use for checking read, edit, and delete capabilities. Defaults to “post”
  • edit_cap – The capability that controls editing a particular object of this post type. Defaults to “edit_$capability_type” (edit_post)
  • edit_type_cap – The capability that controls editing objects of this post type as a class. Defaults to “edit_ . $capability_type . s” (edit_posts)
  • edit_others_cap – The capability that controls editing objects of this post type that are owned by other users. Defaults to “edit_others_ . $capability_type . s” (edit_others_posts)
  • edit_others_cap – The capability that controls publishing objects of this post type. Defaults to “publish_ . $capability_type . s” (publish_posts)
  • read_cap – The capability that controls reading a particular object of this post type. Defaults to “read_$capability_type” (read_post)
  • delete_cap – The capability that controls deleting a particular object of this post type. Defaults to “delete_$capability_type” (delete_post)
  • hierarchical – Whether the post type is hierarchical. Defaults to false
  • supports – An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none
  • register_meta_box_cb – Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback
  • taxonomies – An array of taxonomy identifiers that will be registered for the post type. Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type()

Including Custom Taxonomies

In the following example we include in our Post-Type a Taxonomy with two possibilities; own Tags and categories for Post-Type Movies, the classical tag, without hierarchy and one as category, tag with hierarchies.

function post_type_movies() {
	register_post_type(
                'movies', 
                array(
                        'label' => __('Movies'),
                        'public' => true,
                        'show_ui' => true,
                        'supports' => array(
                                     'post-thumbnails',
                                     'excerpts',
                                     'trackbacks',
                                     'custom-fields',
                                     'comments',
                                     'revisions')
                )
        );
	
	register_taxonomy( 'actor', 'movies', array( 'hierarchical' => true, 'label' => __('Actor') ) ); 
	
        register_taxonomy( 'production', 'movies',
		array(
                         'hierarchical' => false,
			 'label' => __('Production'),
			 'query_var' => 'production',
			 'rewrite' => array('slug' => 'production' )
		)
	);
}
add_action('init', 'post_type_movies');

Definitely a very interesting and useful feature which provides many possibilities to play around with.


Posted

in

by

Comments

112 responses to “First Impressions of Custom Post Type”

  1. Taylor Dewey Avatar

    Yet another step toward a very robust system — this would definitely come in handy (and still may) on a client site I just finished.

    Thanks for the write-up, I was wondering how custom post types were going to work in 3.0

  2. Kris H Avatar
    Kris H

    Pure Awesomness

    I’ve been wanting this for a VERY long time. Had a quick play with it and it’s going to make life sooooooooo much easier.

    I think WordPress can now call itself a CMS. Instead of a blog you hack into a hard to manage CMS.

  3. Dian Avatar

    Well it was about time for this feature.

    We already have a client website based on 2.7 which uses a custom post type, but we had to pay a developer do it.

    I wish this feature came earlier.

    But we better get it later rather than never!

    Yeah!

  4. Ozh Avatar

    That’s a killer post.

  5. John Avatar

    This looks totally sweet. A quick search of 3.0 trunk source doesn’t show an obvious way to filter out posts of a particular type in get_posts(), not like category__in or tag__in and their ilk. How would I request only the posts within a particular user-defined taxonomy with get_posts()?

  6. Mac_Boy Avatar
    Mac_Boy

    @Frank, thanks for the explanation of each parameter. I too have been following and learning from Justin Tadlock’s articles on custom post types and taxonomies.

    Since you’ve done a terrific writeup, would you please insert this info into the official WordPress documentation (codex)? (Unless its already in there)

    I’ve always said that WPengineer tackles the difficult stuff and avoids mimicing the other WP sites. Proved me right again.

    Thanks!

  7. Wes Bos Avatar

    Looking really interesting – I’d love to lose the hacky flutter/magic fields plugins.

  8. Oliver Schlöbe Avatar

    A very very cool wrapup of the Custom Post Type thingy, Frank. I’ve been coming across many question marks on Twitter these days, this post clarifies pretty much all. 🙂

  9. Dalton Avatar

    This is a killer feature for WordPress, I’ve been waiting for it for a long, long time. Thanks for the write up.

  10. matt mcinvale Avatar

    i am soooooooooooooooooooooooo excited for this feature! :):):)

  11. Frank Avatar

    @Mac_Boy: I think we will wait for a post on the codex; maybe it changes little bid until the final release.

    Thanks to all for your nice replies.

  12. Guillermo Avatar

    @John: I have tried using query_posts() and it works really fine. In this example, you can try something like:
    query_posts(‘post_type=movies’)
    and you’ll get a query of all the posts in Movie content type.

  13. Chris Robinson Avatar

    Great post, looking like a powerful new feature. Looking forward to 3.0

  14. Lucian Avatar

    Those are some very good news for WordPress community. I wanted this ability since I first got into WordPress.

    Thanks to keep the rest of us updated!

  15. Dian Avatar

    Once again, a step closer to the ultimate CMS!

  16. Nathan Avatar
    Nathan

    Amazing post! This is the feature I’m looking forward to the most in 3.0 and I am testing it out now with the nightly build.

    Thanks!!

  17. shawn Avatar
    shawn

    Finally! wow this is the final missing piece for me. Man I just wish 3.0 was closer to release.

    What is funny, is just 3 hours ago I was on skype with custom developers and the quotes I received to do this in 2.9 were huge. 3.0 is literally going to save me thousands in development costs. No longer will I regret using wpmu instead of drupal… way to go wp!

    I absolutely love your website as indeed you do tackle the more difficult aspects of wp. Most other blogs are just rehashes of the basics. I learn more coming here for a few minutes than surfing tons of other wp ‘code’ sites.

  18. J Avatar
    J

    A big thanks for this write up. Custom posts + custom taxonomies + open data is a huge game changer.

    The possibilities are endless and it pains me to think of all the potentially great projects we’ll have to pass up.

  19. Tom Hermans Avatar

    This looks really promising. I’m using the pods-cms plugin now, which I’ll probably be using still then cause of the handy cross-referencing, but this is a giant step forward.

    If they now could make a better user control system (assign users not only certain permissions, but also limit their actions to certain pages/posts/…).

  20. kingofpunk Avatar
    kingofpunk

    If we create 2 kind of posts types say : Directors and Movies.
    Can we make directors pages parents of movies pages ?

  21. Ova Avatar
    Ova

    Hi, I am a newer in WP, and I don’t know where to write this lines of code, to create individual post-types. Thanks.

  22. […] nous dévoile quelques nouveautés qui vont apparaitre dans WordPress 2.3. D’abord, la fonction de personnalisation des billets ‘custom post type‘ qui permet d’attribuer un genre à un article. Cette fonction […]

  23. Tommy Avatar

    Wow, I’ve been using the Magic Fields plugin to do this on my Blu-ray site, this will be amazing when it’s native in WP!

  24. Pixcod Avatar
    Pixcod

    This is a good write up, I’ve used PODs before, which was great – but in all honesty I’d prefer this method even though I’m a novice PHP person. Speaking of being novice; when I integrated the supplied code (even the first snippet) I did not see anything change on the Admin side.

    Any thoughts?

  25. Kris H Avatar
    Kris H

    Pixcod – You need to download the latest nightly build of WordPress 3.0 (not recommended for live sites)

  26. palPalani Avatar

    This is the feature I’m looking forward to the most in 3.0. thanks for sharing this great idea!

  27. alex Avatar
    alex

    <3 wowwwww!!

    I ve being waiting for this hack for more than 2 years!

  28. […] WPEngineer.com staat heel mooi hoe je dit kunt toepassen en de register_post_type wordt daar zelfs nog […]

  29. Flick Avatar

    This feature looks fantastic! The thought of being able to modify the post interface to suit the post type is very exciting.

  30. […] Drupal, and how they handle automatic testing and custom data types (for which WordPress has the upcoming custom post types and the pods plugin), to donations (or lack thereof) for plugins. They go in-depth about […]

  31. Jan Egbert Avatar
    Jan Egbert

    If anyone is interested in experimenting with custom post types, try CMS Press. A new plugin that provides an interface for adding post types and taxonomies. It’s still in beta, but the guy working on it has also done some work on the custom post types feature for WordPress.

    http://github.com/voceconnect/cms-press

  32. Iva Avatar

    YAY, AT LAST! I’m excited and this is a great write-up that continues exactly where it should – on Justin’s last year post.

    By the way, why can’t I enlarge your screencaps? I want to see what I’m going to play with before I start playing with it. on the alpha.

    Also props to Jan Egbert, this looks interesting.

  33. […] Preview: First Impression of WordPress Post Types by Frank of WPEngineer […]

  34. […] Combining Post Types and Taxonomies will make WordPress a much more robust CMS option. Check out First Impression of WordPress Post Types by Frank of WPEngineer for more on […]

  35. Lars Bachmann Avatar

    Weehh.. That looks great. I can see a lot of possibilities with custom post types all ready. Can’t wait to get my hands on WP 3.0 🙂

  36. Idealien Avatar

    YES!!!!

    Must get a copy to start playing with it to see how we can take advantage of this through templates to match post types. I’ve been using More Fields for this type of thing in many of my sites thus far but it has its’ shortcomings.

  37. Iva Avatar

    How would I go about having a specific template file for a specific post type? In other words, what to do if I don’t want them to be listed in a specific way and, once one is selected, for that one to be displayed in a specific way (e.g. no date, no author info and definitely no posts’ categories)? Or is it too early to even ask anything like this?

  38. JohnONolan Avatar

    Awesome post – really cool to see this new feature in action!

    @Dian – You should have researched more carefully then, there have been several plugins around for a number of years that have added this type of functionality. No custom development work needed!

    PS. A blog dedicated to WP, but no inline comments? That’s a little strange!

  39. […] Preview: First Impression of WordPress Post Types by Frank of WPEngineer […]

  40. shawn Avatar
    shawn

    check out the new plugin:
    http://wordpress.org/extend/plugins/verve-meta-boxes/

    This is a huge step forward for creating groups of meta boxes. I absolutely love the plugin, and would love to see it extended to work with 3.0.

    The one thing it does not do at the moment, is assign a meta box to a given post_type.

    This means if I create multiple meta boxes, they all show up on the post page, where if the plugin could be moded to ‘attach meta boxes’ to a given post_type, then we finally have the perfect wysiwig input area…

    just an idea….

  41. Nico Avatar
    Nico

    @shawn : you are right. Verve Meta Boxes is the perfect addition to the custom types.

    In real life condition, creating new custom types (with custom taxonomies) but without new per type meta-field-boxes makes no sense.

  42. Kris H Avatar
    Kris H

    At the moment I use custom field template. And he is working to support custom post types 🙂

    http://wordpress.org/extend/plugins/custom-field-template/

  43. slee Avatar

    Excellent post, I cannot wait to get this it will very useful. It will make it even easier for a client to understand how to add news for example and easy for us to style.

  44. timani Avatar

    I program in both Drupal and WordPress, and for me one of the gripes i have had on the WP side was the lack of functionality and the ability to have dynamic content types and more “programmer” oriented tools, functionality and plugins.

    As of late this has changes a lot, this is definitely a step in the right direction. The ability to define custom content types if pivotal for any true CMS. Especially if you see how most modules on drupal such as with the powerful ubercart module extend the default node content type.

    I am sure soon there will be something to rival the views module for Drupal, but this alone is awesome and will likely change the way that A LOT of the current plugins that exists are coded in WordPress and rightly so.

    I am definitely going to take advantage of this, and i think this could be the step that will shake the misplaced title of WP as just a “blogging platform” to a true “CMS”

  45. Idealien Avatar

    @timani – That makes me wonder something wonderful and weird. Where / how will amazing custom content types be shared similar to what the plugin and theme repositories offer?

    Small snippet examples that could become plugins often just get documented as WordPress tutorials on blogs and wonderful sites like wpengineer.com and wprecipes.com. I could see logical arguments that nothing new needs to exist and they would just become part of a plugin, a theme or both.

    This might be a little longer-term question to see if some automated method for custom content types to be added to an installation similar to the automatic update makes sense. I have the same thought for widgets which seem to have fallen into both plugin and theme collections depending on their purpose.

  46. shawn Avatar
    shawn

    I’m working on a client project as I write this, and one thing I cannot find about wp 3.0 is if it has the capability of assigning custom meta boxes to a post_type.

    I created a custom post_type in wp, and assigned taxonomies to it. That part works perfectly even in 2.9.2.

    What I can’t figure out is how to add in the needed input fields such as image/file upload/etc to the post_type.

    I’ve tried the verve meta box plugin which works great, however it only allows me to assign a meta box to either a ‘post or page’ and does not recognize my new post_type as an option to assign the box to.

    Does wp 3.0 take away the need for verve, where I can add in not only taxonomies but custom meta boxes?

    (I know that i can use custom fields, but that is very unfriendly for my site admins, their tech level is >1, and they need a gui).

    What do you think would be the best way to proceed on this?

    –alternately if someone with enough skills took a look at verve, it may be possible to remove the hardcoded post types and have it look for all available ones to assign the box to.. that would be a dream!

    I’m currently using the cms-press plugin to create post_types with taxonomies, and that works awesome. Now just to combine the two plugins.. heaven

  47. illimar Avatar

    Hi! What a great post! I’m trying ut custom post types right now and I have a few questions:

    1. Can I somehow translate the post label? I tried adding using __(), but it doesn’t seem to work – it only dispplays the english version of the text

    2. How can I change or remove the new post type slug? Ie, now i have something like gearhead.ee/equipment/bassikolar-turbosound-tq-425dp/ but I’d like to use gearhead.ee/bassikolar-turbosound-tq-425dp/ instead.

  48. fb Avatar

    Well done, just working on custom post types myself for a new project and your post along with Tadlocks, helps tremendously. Combine this with the new custom menus and we definitely will be saving ourselves a lot of hacking about in future sites that we build for clients.

    Keep up the good work

  49. Ash Blue Avatar

    This really gets me excited, I’m designing a church for a website and I’ll now be able to create sections like events, news, and other cool things, It will make their lives a lot easier.

  50. Nicolas Avatar

    It is now required to register supports for the “title” and “editor” if you need them.

  51. Michael Avatar

    @Nicolas: no 🙂

  52. Konstantin Avatar

    You might want to add the singular_label parameter so that it would say ‘Add Movie’ but ‘Movies’ in the menu 😉

    Great post!

  53. matt mcinvale Avatar

    @Michael, it looks like Nicolas is correct. I was getting a mostly blank page and then adding title & editor to the supports array fixed it.

    What is the option to get the slug to display?

  54. matt mcinvale Avatar

    disregard: looks like the slug is auto-displayed with the title.

  55. Michael Avatar

    @matt @Nicolas: that snippet brings me a full testpost ui:

    register_post_type(
    'testpost',
    array(
    'label' => Testpost,
    'public' => true,
    'show_ui' => true,
    'exclude_from_search' => true,
    'supports' => array(
    'post-thumbnails',
    'custom-fields')
    )
    );

    Newer as this article is the singular_label.

  56. matt mcinvale Avatar

    And you’re using the latest build? That’s very bizarre. Without those options neither are displayed for me.

  57. Michael Avatar

    matt, just updated with 13753, same shit. Just custum_flieds ui 😉

    'supports' => array(
    'post-thumbnails',
    'custom-fields',
    'editor',
    'title'
    )

    That works now.

  58. Michael Avatar

    That was changed:

    if ( ! empty($args->supports) ) {
    add_post_type_support($post_type, $args->supports);
    unset($args->supports);
    }...

    And post-thumnails support dosn’t work anymore. No clue why.

  59. matt mcinvale Avatar

    Heh, gotta love the Alpha stuff. 😉

    You wouldn’t happen to know where they have docs on this stuff? Specifically looking to assign a template to a post type.

  60. […] Little went over an example using some sample code from https://wpengineer.com/impressions-of-custom-post-type/, head over there to read more about post types. This will change the way you create CMS sites using […]

  61. Matthew Avatar
    Matthew

    @Michael try
    'thumbnail'
    instead of
    'post-thumbnails' , it works for me.

  62. Pablo Almeida, consultor de SEO Avatar

    Even as a beginning, it’s too little to compete with Drupal and Joomla… 🙁

    I still want to use the Pods CMS. The Automatic could rely on this plugin to develop custom types module.

  63. […] Schau hierzu –  how to create custom content types. […]

  64. Frank Anthony Avatar

    How do you move posts from one post type to another?

    Or, more specifically, how do you move an old post to a new post type?

  65. radiaku Avatar
    radiaku

    Hey, can we adding some nice custom write panel only on that post type.

    like on this.
    http://wefunction.com/2009/10/revisited-creating-custom-write-panels-in-wordpress/

    Any hack 😛

  66. Xevo Avatar

    Would be awesome to see TDO Mini Forms to use this feature quick, that way we can make wikies etc. 🙂

  67. […] Data Types Plugin of Choice: More Fields, PODS, WordPress 3.0! Yes it is possible to train users to select a strangely titled custom field and populate it, but it […]

  68. […] 1 WP Engineer skriver om custom post […]

  69. […] und können direkt im Loop berücksichtigt werden. Einiges zum Thema habe ich schon bei WPD und WPEngineer […]

  70. Leon Poole Avatar

    Custom fields will really open up WordPress to make it easier to do more ‘complicated’ and ‘custom’ websites with the CMS – I’m testing this out currently too.

    Would love to see more posts/examples/demo’s on Custom Taxonomies 🙂

  71. Peter Ng Avatar

    @radiaku for the custom write panels all you gotta do is change the 4th parameter of the add_meta_box function ($page) to the name of your custom post. in this case you would change it to ‘movies’.
    http://codex.wordpress.org/Function_Reference/add_meta_box

  72. Denis Avatar
    Denis

    What should I do to show blog custom post types from users on my network (MU)?

  73. kingmagicl Avatar

    This is a feature of wordpress. It’s is very good but this article writes error. Coding error syntax. You should write :
    function post_type_movies() {
    register_post_type(
    'movies',
    array('label' => __('Movies'),
    'public' => true,
    'show_ui' => true,
    'supports' => array(
    'excerpt',
    'trackbacks',
    'custom-fields',
    'editor',
    'title'
    )
    )
    );
    register_taxonomy_for_object_type('post_tag', 'movies');
    }
    add_action('init', 'post_type_movies');

  74. […] Custom Content Type “Content type”, also commonly referred to as “post type”, is a reference to the kind of content that is being captured and then published through WordPress. The content types that come in a default install are posts, pages, links, and media. Theme developers have been hacking their way into custom content types through their own programming or the use of plugins like Pods, More Fields, and Flutter. With the release of WordPress 3.0 has finally come a native way to create custom content types, that can capture custom values, in a custom write panel. To read more about how this works, Frank from WPEngineer.com has written a great article, First Impressions of Custom Post Type. […]

  75. […] the post page and pre-fills some options based on your typical usage.  Read more about it on the lead developers site.  I will suggest that most average bloggers will not be to interested in these options, or […]

  76. Jessica Avatar
    Jessica

    Shouldn’t register_post_type() work in 2.9? The Codex lists register_post_type() as “Since 2.9.”
    http://codex.wordpress.org/Function_Reference/register_post_type

  77. Gavin Hall Avatar

    This is great. Tried putting a few of these samples into functions.php file of latest 3.0 build but admin menu wouldnt show up as on your screenshots. Is this an extra step?

  78. […] und/ oder Tags (nicht hierarchische Taxonomy) für den neuen Ty (hier Fragen) anlegen. WP Engineer zeigt das sehr anschaulich am Beispiel Filme, zu dem man Schauspieler-Kategorien (Actor) und […]

  79. Lars Avatar

    Great info. I can’t wait to try this out. I’ve got WP 3.0 beta installed locally but haven’t got around to testing the custom post type yet.

    After reading this I’ll have to give it a go…eagerly anticipating more useful functions, code snippets and plugins to take advantage of this.

    I’ve been waiting for something like this for ages to be able to create a usable admin allowing users to add custom post types. Using custom fields was always too fiddly and unintuitive for novice users.

    I also tried using Flutter and Pods CMS but as powerful as they were never user friendly enough to use for client websites or for user contributed content on sites. Hopefully custom post types will give us the flexibility to finally create usable CRUD interfaces for external users.

  80. […] Drupal, and how they handle automatic testing and custom data types (for which WordPress has the upcoming custom post types and the pods plugin), to donations (or lack thereof) for plugins. They go in-depth about […]

  81. yeswework Avatar

    this functionality is of course very welcome, but the policy of having custom post types defined within functions.php makes no sense. these definitions aren’t so much a part of a site’s theme as a part of its underlying content/database.

    surely custom post-type definitions (and likewise custom taxonomies) ought to be in a separate theme-independent module, allowing the user to change theme but maintain the site’s content and hierarchy?

    moreover: isn’t it wasteful to have these definitions as PHP code which executes repeatedly and redundantly every time a page request is made?

    one more potential drawback of this method: if you started changing the post_type definitions once a site was already populated with data, you could quickly lose touch with the contents of the underlying database, with no way of cleaning it up or getting back to where you were.

    in my view these features should be configurable either through a GUI in the WordPress admin, or through YAML (or similar) but away from anything to do with the theme.

    any comments? have I missed something?

  82. KmaN Avatar

    I’m glad I read the comments all the way down as the last comment I read by @yeswework opened my eyes to what most of us seem to have been blind about.

    You bring up valid points @yeswework… and I’m interested to see what others may respond to this, including @Frank.

    Nonetheless, I am excited about this feature and I look forward to messing around with it with my fresh installation of WP 3.0.2 beta.

    Cheers.

  83. Richard Sweeney Avatar

    Thanks for a great article! This whole custom posts malarkey is really exciting.

    Here a question: 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 2 categories : ‘jazz’ and ‘classical’. How can I only display the ‘jazz’ entries?

    register_taxonomy( 'categories', 'music', array( 'hierarchical' => true, 'label' => __('Categories'), 'query_var' => 'cats' ) );

  84. Frank Anthony Avatar

    @Richard Sweeny : Just add ‘post_type’ to your query.

    $jazz = new WP_Query(array('post_type' => 'Music', 'category_name' => 'jazz'));
    while ($jazz->have_posts()) : $jazz->the_post();
    ?>

    // display post stuff here

  85. […] you can only create pages and posts with WordPress. In 3.0, you can create your own custom post types, and set up the appropriate fields to go along with each. When a user chooses a new post type, […]

  86. donalyza Avatar

    Anyone knows how to exclude a category in a featured post? I’m trying to exclude ‘misc’ cat. I only know how to exclude a post.

    Here’s my code
    array('post', 'portfolio'), 'showposts' => 3 )); ?>

    Any help will be greatly appreciated. Thanks.

  87. Frank Avatar

    query_posts('cat=-2') exclude the categegory with ID 2.

  88. Damian Avatar
    Damian

    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??

    HELP

  89. JanvierDesigns Avatar

    I knew right away that going the wordpress way I couldn’t go wrong! Ok. . .this post just gave me some sensation one has only after taking in a few substances! Wow .. . . Right now I am working on a client’s website and we need to use “special types of posts ” (Events to be specific) and this could come in so handy.

    WordPress team = I don’t know… no words… Love you guys!

  90. Mike Avatar
    Mike

    How is it possible to add the categories box to the custom post type? This doesn’t show up by default like it does with regular posts. I have added the categories field to my custom post type menu and they are all displayed as uncategorized which tells me by default unless you select a category it goes uncategorized. How do I add the categories box so I can select a specific category for a custom post? For example a featured category so that if category = featured I can show featured posts.

  91. Adam Hansen Avatar

    I am using the code the_author_posts_link and it is not working for a custom post type I setup. I have authors posting normal posts and also this custom post type (photos). I made sure to set photos as a post type and not page. When clicking the link though it does not return any of the custom posts types. How can I set that up correctly?

  92. Christopher Hertz Avatar

    Quick heads up that with the WP Easy Post Types plugin you can create WordPress custom post types on the fly with an easy to use interface. Then manage custom fields and categories for your post types.

    It is a fairly powerful plugin. For example, you can create custom fields without having to create keynames and values. Output custom types simply by using the preformatted template tag for your field or create your own. One single call to display any field in an output. Additionally, once you have created a custom field this field is now available every time you edit/create a custom post type. This feature saves you time and gets rid of the frustration associated with custom fields that cause many people not to use them. Many out of the box field types available, or create your own through the plugin API.

    You can download it at wordpress.org or learn more about it at http://www.wpeasyposttypes.com.

  93. Nico Avatar
    Nico

    I wrote a message on wordpress forums, about custom post types UI plugins.
    It’s a first step of a benchmark of available solutions.

    Check it out : http://wordpress.org/support/topic/414967

  94. Leon Avatar

    For some setups you have to add the function

    flush_rewrite_rules( )

    otherwise it couldn’t find the post

    thanks for nice post!

  95. Erik Avatar

    What about using plug ins with custom post types? Apparently this was never thought about during the development process. I mean I love the idea of creating a custom post type for podcast or screencast but if I can’t use the plug ins I already have in place to handle the media of those type why in the world would I still create a custom post type ?

    Is there a solution for adding plug in meta boxes to custom post type that any one has heard of?

  96. Gaston Suarez Duek Avatar

    Is there any way to use page attributes in custom post types, I have order attribute, but I need Parent attribute, please help, Don’t know if its possible!

  97. […] 3.0 has improved support for custom post types, which would make it very easy for someone to build Tumblr-like functionality into WordPress by way […]

  98. byronyasgur Avatar

    question: does register_post_type need to be called from add_action(init or is there another one – i want to use a form to register a custom post type – any ideas

  99. Agus Suhanto Avatar

    Do you know how to add custom fields automatically when registering custom type?

  100. byronyasgur Avatar

    thought i’d answer my own question as i just came across it and had figured it out —- register_post_type needs to “register the post type” every init and so does have to be called from init ( the only way to use a form to register a custom post type is to save the form output to the database and then call a function on init to see if the data is in the (options) table and if it is then register_post_type

    @yeswework. i love the new technology but you are giving me something to think about — although obviuouly plugins can register post types too and i think themes should be able to “generalte” their own post types but i think that admins should be able to register post types in the backend

  101. byronyasgur Avatar

    @Gaston Suarez Duek is it not set when you set up the array to do the register_post_type ?

    $….. = array(
    ‘hierarchical’ => true,

    to be honest i could be wrong but i’m nearly sure its’s somewhere down that road anyway – yes i definitely got a post type to allow parents/children definition in the posts and then turned it off somehow … think it was the above

  102. khaledhakim Avatar

    I’m having a problem with Custom Post Type Categories…

    Setting the scene:
    lets say I have a custom post type of Books… and inside that custom post type I have created categories… Let’s say I have categories A B and C.

    What I want:
    Display on the home page, or any other page for that matter, listings (posts) in a particular category of a specific Custom Post Type.

    Question:
    How can I call on the, say home page, all posts of custom type Books in category A only?…

    Been looking all over for the answer to this and have found none. Look forward for some help … anyone ? 🙂

  103. Nico Avatar
    Nico

    @khaledhakim :

    Let’s say, your custom type post slug is “book”, and your custom taxonomy slug is “book_category” and that you only want books from the category “philosophy” :

    query_posts(‘post_type=book&book_category=philosophy’);

    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ..
    endwhile; else:
    ..
    endif;

  104. […] excerpt field, and eliminate the WYSIWYG editor? You can do that.More reading on Custom Post TypesFirst Impressions of Custom Post TypeCustom Post Types in WordPress 3.0Custom Post Type UI Plugin for WordPressExtending Custom Post […]

  105. Matt Avatar
    Matt

    Is there a way to add custom fields to the custom taxonomies?

  106. Rocky Avatar
    Rocky

    @Matt (comment 88) — I think the answer to that is no. Can you describe more what you are trying to accomplish? Because I think adding custom fields to a custom post type instead of a custom taxonomy is probably what you should be doing.

    To a previous question regarding where to do all this registering, it makes more sense to create it in a plugin rather than in the theme’s functions.php file. I’m working on a video plugin to create a video sitemap and another plugin to adapt the Open Video Project code to read video data from the video sitemap so a video gallery can be created. Creating a custom Video post-type was easiest right in the video sitemap plugin file.

  107. Marco Avatar
    Marco

    How do you add the custom type post for search?

  108. Brij Avatar

    Nice Post!!!

    I have created a project collection theme based on this custom post type feature.

    See following to download:

    http://www.techbrij.com/342/create-project-collection-theme-wordpress-3-custom-post-type

  109. […] First Impressions of Custom Post Types von Frank Bültge bei WPEngineer. […]