You may have heard of a custom post types for WordPress and wonder what they are all about (or is that just me, I sometimes forget the real people who live outside tech-land sometimes don’t think in geek).
In this post I’ll give you a run down about custom post types and how they can help you.
What Is A Custom Post Type
You can extend the way data is saved in your WordPress database by adding custom post types. Instead of the standard post or page layouts, you can extend the database and store data in a way that is more meaningful to you and your requirement.
An example is probably required here. Imagine you want to extend your site and have custom posts types of events. An event has a title, details, location and a date. This is a little different from a standard post, so we need a custom post type.
Lets Step through this example and talk about how this events custom post.
How To Create Custom Post Types
There are a number of ways you can create custom post types:
Code them up in your theme – you can write a function for your themes function.php file which creates a new custom post type.
Write a plugin – you can write a custom plugin which creates your custom post type and loads them up when the plugin is activated.
Plugins – there are plugins out there there that allow you to create your own custom post types. They allow you to create CPT without the need to understand the coding required. My favourite is this GUI custom post type creator.
All of these approaches do the same thing. Some code will be created and this will run when you site loads, new posts types are created and a menu item added to allow you to add content.
They use the register post type function, here are full details if this your thing.
Adding Custom Post Type Data
Once your code has been added, there will be a menu option to add, edit and amend your custom post type data.
You will get a version of the post editor that allows you to add your content. It is the same editor we use for posts and page so there is not learning curve to add custom content.
Displaying Custom Post Type Data
Depending upon how your current theme is coded, your existing archive templates will display custom post types, but if you want something specific you will need to code up a template or add a custom query to existing pages templates.
For example if you want to show custom post types on your home page rather than blog posts, you would need a custom query loop.
If you don’t have the coding skills to write your own custom templates, Loop Buddy may be of help.
Re-Using Existing Post Functionality
We can re-use existing post functionality in our custom post types, for example if you want comments on your data, you can re-use that functionality. This is setup when you create your custom post type.
Extending Post Data With Custom Fields and Meta Boxes
You can also add new data types of your custom post types and have meta boxes. Here is an example from a plugin I use called In Post Ads which has some custom meta boxes.
As you can see a custom meta box has been added which gives us a series of check boxes.
It’s Not For The Feint Hearted
As you can no doubt guess adding custom post types requires a certain level of technical skill to code up theme files, plugins or to create templates to display content.
Some Examples I Have Built
The way you can use custom post types is limited only by your imagination. Here are some of the projects I have worked on:
- Events - the event has custom coding to have an event date and sort on that date, as opposed to the published date which will not show future events
- Guides – I wrote a custom plugin to add and manage downloadable PDF guides
- Bibliography – I wrote custom code to modify a bibliography for scientific journals and publications. This has lots of custom meta for citations and references.
Custom post types move WordPress away from being just a blogging platform to being a fully functional content management system.
I don’t want to throw too much at you in one post, but next up I’ll talk about custom taxonomies. You can create custom ways to organise your custom post types.
Need Help With Your WordPress Site?
Why not hire A WP Dude to help solve your WordPress Issues, only $99 per job