Posted on

WordPress Basics: Custom Post Types

You might find it hard to believe, but for an experienced WordPress developer trying to see something from a new WordPress user’s perspective is almost as difficult as it is for that user to develop a theme or a plugin. Still, dropping your standard hat and putting a different one on every now and then is rarely a bad thing. So let’s take a look at one of WordPress’ most important features – post types, focusing more on the WHYs of using custom post types than the HOWs.

What Are Post Types?

WordPress stores all of its posts into one database table called wp_posts. That includes all of your default post types (posts, pages, navigation menu items, attachments and revisions) and any other post types registered by your themes and plugins. Latter ones are known as Custom Post Types, indicating that when you install a new WordPress site they don’t exist.

Custom post types can be used for anything and basically they’re just posts that have one value that tells WordPress which post type they belong to. This of this as nations – they were made up to keep us apart, even though deep down we’re all the same. Luckily, posts and pages will never go to war with navigation menu items.

Why You Should Use Custom Post Types

A few years ago WordPress started shifting away from a blogging platform and towards CMS. This allowed users to install plugins and themes* that registered custom post types and separated content in more logical ways. Sure, you still can use standard posts or pages to display your latest portfolio projects, events or testimonials but it doesn’t make too much sense to do it that way.

A better way is to use custom post type because this way you can have a separate section of your WordPress dashboard for portfolio, event management or testimonials. You don’t have to go through hundreds or thousands of posts to find your portfolio projects if you can have them all listed in a separate dashboard screen.

*Themes should never handle custom post types. Unfortunately, finding a commercial theme that doesn’t do this seems more difficult than winning the lottery. Need convincing? You can read more about why themes shouldn’t handle custom post types or what happens when you deactivate a theme that does.

Using Custom Post Types the Right Way

When it comes to registering custom post types there really is only one good way to do it – using a plugin. Let a theme do it, decide to change how your website looks, replace the theme and they’re gone. Use a plugin and you won’t have this problem.

Now that you know you will, and more importantly why you will use a plugin there’s two ways to do it. You could look for a plugin that handles specific functionality you need. For example, if you need to add e-commerce to your site, you might want to take a look at WooCommerce. Such a focused plugin can do most of the work for you and the only thing you might need to do is find a theme that supports your plugin (not easy, unless it’s a wildly popular plugin like WooCommerce) or tweak any other theme so it displays custom post types registered by the plugin the way you want them.

If you’d just like to use a custom post type so your projects/events/testimonials don’t mix with standard posts and pages you can use a plugin like  Custom Post Type UI or GD Custom Posts And Taxonomies Tools to register your own custom post types. They will look exactly like standard posts but having everything in your dashboard organized is worth the trouble. Of course, it is possible to adjust your theme so it displays custom post types the way you want them, but it will take some PHP and CSS skills or hiring a developer to do it.

The Issue With Custom Post Types

They are great and I can’t remember last time I saw a website without them, but one thing lacking is any sort of standardization. A plugin can register my_plugin_custom_post_type, another one can register some_other_custom_post_type, then there’s the theme that registers five more custom post types, even though it shouldn’t.

This is both good and bad. Good, because there are no constraints to how developers approach custom post types, leading to creative solutions. Bad, because there are no constraints to how developers approach custom post types, letting each one do it his way, sometimes forcing WordPress users to figure out many ways to skin a cat (English language is weird), when all they need is one.

The way I see it, best solution to this problem is having more custom post type WordPress plugins become a standard, like WooCommerce or Contact Form 7. Ever since WooCommerce became so widely accepted you don’t see too many plugins trying to handle “products” post type. I’m sure some day we’ll have such plugins for portfolio projects, events and pretty much anything else, forcing theme developers to work on making sure their themes work WITH custom post type plugins, not compete against them.

Featured image credits: Flickr

Slobodan Manic
I love working with WordPress and doing it the right way. Themes and plugins I develop have a common #1 goal: Keeping it as simple as possible for users to publish their content.
Slobodan Manic

@slobodanmanic

Web analytics freelancer, data visualization hobbyist
@NiklasHogefjord Thank you! A decent day so far 😁 https://t.co/6WtxzIAwF2 - 3 months ago
Slobodan Manic
Slobodan Manic
Slobodan Manic

Latest posts by Slobodan Manic (see all)

9 comments WordPress Basics: Custom Post Types

  1. Very good points you have here, and I totally agree. Sometimes I wish WP was a bit more rigid in what is allowed to do, and how to do it. I just removed up 800 entries in wp-options in one of our WP installs, and one template that we used 4 years ago, had left 60 tables hanging there for nothing.

    Obviously this creates a lot of cleaning up in the db.

    By the way: Thanks for the tip on WPDBSpringClean. It was very helpful.

  2. Certainly sounds like the right approach. Do you have any suggestions on the best way we designers find these best-of-breed plugins? We found that themebeans.com has started a set of plugins (portfolio, tweets, shortcodes and instagram). Theirs are free, but a fee would be reasonable.

    1. The ones ThemeBeans does look good. We’re working on, and really finalizing our own and hope to have it released this month. Our approach is slightly different, the plugin handles several functionalities, it’s modular, so you can use only the functionalities you want, and the idea is to make functionalities connected. For example, if you have Testimonials and Portfolio modules active, you can assign a testimonial or category od testimonials to a project.

      We’ll announce it as soon as we think it’s ready for public, so keep an eye on it here.

  3. Great post!

    I’m struggling with the thought process on displaying custom post types in a portfolio plugin shortcode while maintaining pagination, single post type pages and such without resorting to a custom page template, any tutorials/plugin examples you approve of? ( Otherwise, I’d need to bundle page templates with my plugin which isn’t ideal )

    1. I think there’s really two options, shortcodes or page templates. True, page templates are not ideal, but I don’t think they are bad.

      It really depends on who your target group is. If you want to have theme developers accept your plugin and make themes that are compatible with it, then plugin page templates, with option for themes to override them (check how WooCommerce does this) is the way to go. If it’s a plugin you’d like to package and target end users shortcodes are probably easier for them to use.

  4. I really liked your thoughts on custom post types i’m new to WP and i’ve just started wrapping my brain around custom post types however i’m still uncertain how to decide which or scenarios would require a custom post type.

    I get that if they don’t fall in line with basic pages or posts that you would more than likely need to use a custom post type it’s like saying if you need a page that does more than pages or posts could handle by default use a custom post type, is that correct?

    But i’ve also heard and seen people use custom post types for simple things like handling “Testimonials” this concept is interesting to me because it extends the notion that custom post types aren’t just for pages that require lots of custom fields but also for simple modular pieces that you could include on any page but manage from one central location such as the case of “Testimonials” so that’s where i got a bit to questioning.

    I want to use a small jquery slider that will be full width of my content area (980px) that has a custom height and 4 images that link to a respective slug or permalink. Therefore in my mind i would have to create this jquery slider as a custom post type slider so that my client can edit a) the image thumbnails and b) add a link to that image. Using someone else’s plugin could also be an option but because i’m so new that would require me having to figure out how to customize that plugin to meet my dimensions (which you can see from my website link and scrolling to the bottom the jquery is not active yet but the idea is to have it scroll automatically displaying thumbnails that will link to slug or permalink pages) otherwise i thought building the slider myself and making it into a custom post type would be the way to go.

    Am i think about this the wrong way?

    I also have a question, and i realize this is not a forum, but in the image i’ve included below if i wanted the client to be able to edit that content in a WYSIWYG editor should i still create a custom post type for this or is this more along the lines of a widget?

    http://kualitydesign.com/clients/dcinsideout/custom-post-types.png

    Thanks to anyone with that would help me understand this matter:)

  5. Hi. I found your explanation very useful.
    I want to have more interaction with the final users of a wordpress site. So I don’t know if I must use “custom form” plugin or I must creat custom type with custom fields and taxonomies. The tricks is that the client want their records/informations exported in CSV/XLS format monthly. But, we know that custom form and some custom types/fields/taxonomies plugins create their own tables so what about this?
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.