Slides of my Custom Post Types talk WordCamp NL 2012

This talk was the only one of my three talks that was planned in the Beginners track. So, I expected a different audience, different questions and therefore prepared a talk showing the basic usage of Custom Post Types, Taxonomies and Meta Boxes. This approach proved to be a great idea, I think everyone walked out having learned something new.

With Custom Post Types being such a powerful technique, I planned a talk that consisted mostly of a demonstration. Real examples work better in such a talk than pure words.

register_post_type() function

We had a good look at the register_post_type() function and lots of arguments that it will accept. In the Codex you can find the full list of arguments that can be used with that function and what they are used for.

The example code

I choose to create a plugin that registers a post type for recipes. Feel free to download my example code here: recepten.php to run/edit/break the code by yourself.

In that example code, I’ve also attached three theme files: archive-recept.php, single-recept.php and loop-recept.php. These files are mostly based on TwentyTen and can be added to that theme for testing. Note that this is a general bad practice and you should always create your own theme, or at least make it a Child Theme.

Please note: This code is not completely tested, is not 100% written according to the WordPress Coding Standards and could use a little function prefixing to minimize the risk of having duplicate function names. Use this code for educational purposes only.

This plugins also adds a single meta box, created for the recipes post type, to the default ‘page’ post type. We did this while running the code and never got more testing out of it than seeing the meta box appear. You can quickly hide it there, by commenting line number 98 in the plugin file. The function will no longer be called.

The slides

[slideshare id=12149534&doc=custom-post-types-120325113951-phpapp01]

About this site

Noticed how lightning fast this website is? It's powered by a Digital Ocean VPS and they are awesome. Go check it out (and get $10 in credits for free when signing up via this link)!