• Categories
    • Tutorials
    • Beginners Guide
    • WordPress News
    • WordPress Security
    • Best WordPress Plugins
    • WordPress Themes
    • Product Reviews
    • WP Tips & Tricks
  • Guides
    • Start a Blog
    • Make a Website
    • WordPress Hosting
  • WordPress Hosting
    • A2 Hosting
    • HostGator
    • Bluehost
    • Cloudways
  • Managed Hosting
    • WPEngine
    • WPX
    • Kinsta
  • Coupons
    • WPEngine
    • Flywheel
    • Cloudways
    • A2 Hosting
    • WPX Hosting
Beginners Guide

An Introduction to Custom Post Types in WordPress

Last Updated on: February 21, 2016 Rachel Adnyana 3 Comments

An Introduction to Custom Post Types in WordPress

If you’ve just started tinkering under the hood of WordPress, you’ve probably come across custom post types or you may have noticed that many themes come with their own custom post types. If you’re wondering what exactly a custom post type is and what is it for, you’re not alone!

In fact, the phrase “custom post types” is a bit of a misnomer – a post type is really just another word for “content” and doesn’t necessarily have to be a post as such. wordpress-custom-post-types WordPress comes with five different post types as default:

  • Post
  • Page
  • Attachment
  • Revision
  • Navigation menu

Since WordPress 3.0, it has also been possible to add your own custom post types with their own appearance, properties and behaviors.

Why Do You Need Custom Post Types?

Once you start using WordPress to build sites other than basic blogs, it won’t be long before the default post types can seem quite restricting. In general, it’s recommended to use “post” for blog posts, news updates and the like, and “page” for static informational pages such as your “About” page and contact information.

This is fine for most users, however if you want to create some new content that doesn’t fit neatly into the category of “post” or “page”, this is where custom post types come in. There are many reasons why you might want to create your own custom post type in WordPress. For example, if you’re building an e-commerce store, it would be logical to create a new “product” post type, rather than using the standard post or page content. Some other examples of content you may wish to develop a custom post type for are:

  • User profiles
  • Reviews
  • Testimonials
  • Resources
  • Events
  • Property listings

There’s really no limit to the uses of custom post types and their power lies in the fact that they are truly “custom” and unique to the requirements of your website. Using custom post types extends WordPress beyond a simple blogging platform and allows it to become a fully-fledged CMS.

How to Create a Custom Post Type

Custom post types can either be created manually by editing the functions.php file of your WordPress installation, or by using a plugin to do the dirty work for you. For manual creation, you need to use the register_post_type() function which enables you to define a new post type and specify labels, features and availability. Here’s a code sample for creating a product post type from the official WordPress Codex:

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
)
);
}

While you can name your new post type anything you like, it’s important to follow the WordPress naming guidelines when using the post creation function. The identifier should be prefixed by a namespace linking it to the plugin, theme or website that will be using the custom post type. This is to prevent any conflicts with other custom post types that may be introduced from themes or plugins you install. In the example above, you can see that the post type has been registered as “acme_product”, rather than just “product”. Be aware that the identifier should not exceed 20 characters and you should not use “wp” as your identifier, as this is reserved for internal WordPress objects and functions.

There’s more information about setting up custom post types manually over at the WordPress Codex. There’s also a handy post type generator available for free use at GenerateWP, which can really speed up your coding time so you simply need to cut and paste the generated code into your functions.php file. Check out the provided examples for some ideas of how it can be used. If you’re not comfortable with using PHP or editing your WordPress files manually, there are several plugins that will make things easier for you. These plugins are all very to use, allowing you to create a new custom post type simply by typing in the name and selecting from various options: custompress-posttypes

  • CustomPress is a premium plugin from the team at WPMUDev and describes itself as the “ultimate plugin for transforming WordPress from a blogging platform into a full blown CMS”. The plugin allows you to easily create a range of post types with their own custom taxonomies, custom fields and other customization options. It also generates the code for you so that you can use it for generating custom post types to use in your own theme files. CustomPress costs $19 or you can join WPMUDev and have access to all 350+ of their plugins for $39.60.
  • Types is a free plugin that allows you to create and manage custom post types and custom fields easily. Types also has some extra handy functionality such as custom fields and the ability to define relationships between different post types. Combined with the other Toolset plugins, it gives you the power to create a completely custom CMS built on WordPress.
  • Pods is a content development framework that includes functionality to create custom post types and fields. There’s also the option to create advanced custom types that are completely separate from the WordPress system. Pods is free to download and use.
  • Custom Post Type UI is another easy to use plugin that creates a graphical interface for you to register custom post types and taxonomies.

All these plugins do a great job at simplifying the job of creating custom post types so it’s down to personal requirements and preference which one will suit you best – I suggest you download two or three and try them out.

Custom Taxonomies

taxonomy Using custom taxonomies is an optional way of categorizing your new custom post types instead of using categories and tags, as you may do in a normal blog post. Both tags and categories are a type of taxonomy but they may not necessarily work for your new content types and this is why you may want to create a new custom taxonomy. For example, you may wish to create a “product” post type for an e-commerce store and then create several custom taxonomies such as “product-type”, “brand”, “material”, “size” etc. Taxonomies can be created using the register_taxonomy() function in your functions.php file. Here’s an example for creating a “people” taxonomy:

function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
'post',
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);
}
add_action( 'init', 'people_init' );

most of the aforementioned plugins will also allow you to create custom taxonomies from the interface, or you can use a plugin like Simple Taxonomy.

Custom Post Type Templates

Creating a custom post either manually or via one of these plugins will only set up the backend structure of the custom content. To control the way each of your post types looks, you will also need to create a template. WordPress comes with several templates to display the default post types in different ways. For example, the default post type can look different depending on whether it is viewed with the “single” post template or the “archive” post template. New custom post types will also use these template files as default unless you create a different one to use.

To create a new template file for your new custom post type, simply create a new file called single-posttype.php where posttype is the identifier of the custom post (for example, “single-acme_product.php” using the example above). If WordPress does not find a template file matching this name, it will default to the normal single post template. If you’re new to creating custom page templates, you’ll probably find it easiest to start with the code from the default single.php template and edit it to suit your needs. The WordPress Codex has all the information you need to know about creating and using templates within WordPress.

Conclusion

As you start to understand the power of custom post types, you can see how WordPress can easily be converted from a basic blogging system to a complex custom CMS. Using custom post types, taxonomies and templates in your WordPress themes and sites gives you power and flexibility to create whatever kind of site you like. Have you tried out any of the plugins mentioned above? Any other tips for working with custom post types? Please share them in the comments!

Image credits: Ian Ruotsala

+ Share
Disclosure

Rachel Adnyana

Rachel is a web-developer-turned-writer who has successfully convinced many clients to switch to WordPress over the years. She blogs about her life as an expat in Bali at How to Escape.

Related Posts

Back to all articles
  • 10 Best WordPress Hosting Options Compared for 2022 (Pros & Cons)

  • How to Use Laravel Valet for Local WordPress Development on macOS

    How to Use Laravel Valet for Local WordPress Development on macOS

  • What Is the DNS? A Confused Users’ Guide to the Domain Name System

    What Is the DNS? A Confused Users’ Guide to the Domain Name System

Coupons

View more deals
  • 10% OFF

    Elegant Themes Coupon

    You can’t move within WordPress circles without coming across E
    Get This Deal
  • wpengine coupon
    20% OFF

    WP Engine Coupon

    If you’re in search of a WordPress hosting company that deliver
    Get This Deal
  • Kraft Plugins Coupon Code
    10% OFF

    Kraft Plugins Coupon

    Business websites and WordPress go hand-in-hand. Of course, you w
    Get This Deal
3 Comments Leave a Reply
  1. Harri Bell-Thomas says

    May 20, 2014 at 8:50 pm

    Thanks, Rachel! A very interesting and useful article.

    Reply
    • Rachel Adnyana says

      May 22, 2014 at 7:12 am

      Thanks Harri! Glad you found it useful 🙂

      Reply
  2. Jody Raines says

    July 15, 2014 at 3:21 pm

    Thanks for breaking this down and making it easy to understand. I can see several ways that I can extend WordPress using a custom type, and especially appreciate your sharing some plugin tools that can help make this easy. Great article.

    Reply

Leave a Reply Cancel reply

Full Disclosure This post may contain affiliate links, meaning that if you click on one of the links and purchase an item, we may receive a commission (at no additional cost to you). All opinions are our own and we do not accept payments for positive reviews.

THE BEST OF WPKUBE

Some of the best content we have published so far.

BEGINNER GUIDES & REVIEWS

1How to Start a Blog in 2022 (Step by Step Guide)
28 Best Cheap WordPress Hosting Providers in 2022 (From $1.99)
310 Best WordPress Hosting Options Compared for 2022 (Pros & Cons)
48 Best Managed WordPress Hosting Compared for 2022
55 Best WooCommerce Hosting Providers Compared in 2022 (All Budgets)
6Top 9 Landing Page Plugins for WordPress (2022)
79 Best List Building Plugins for WordPress In 2022
8How to Fix the 500 Internal Server Error on Your WordPress Website
9Beaver Builder Review: Is it The Best Page Builder Plugin for WordPress (2022)?
10Thrive Themes Review: A Look At The Full Membership
11OptimizePress Review: Create Landing Pages with Ease
12How to Make a Website: Complete Beginner’s Guide
13WordPress.com vs WordPress.org: Which is Best for Me?
14Top 22 Best Free Stock Photo Resources For Your Site
1517 of the Best Google Fonts for 2022 (And How to Use Them in WordPress)
16How To Fix ‘503 Service Unavailable’ WordPress Error
1711 Best Contact Form Plugins for WordPress in 2022
18How to Add a Custom Logo to Your WordPress Site
19How to Fix Error Establishing a Database Connection in WordPress

WPX Hosting: 50% OFF

Save 50% on WPX Hosting using our exclusive coupon code.

Get this Deal

Flywheel(our review)

Featured In Forbes Huffpost Entrepreneur SEJ

About WPKube

WPKube is an online WordPress resource which focuses on WordPress tutorials, How-to’s, guides, plugins, news, and more. We aim to provide the most comprehensive beginner’s guides to anything about WordPress — from installing plugins, themes, automated installs and setups, to creating and setting up pages for your website.

We have over 500+ tutorials, guides, product reviews, tips, and tricks about WordPress. Founded by Devesh Sharma, the main goal of this site is to provide useful information on anything and everything WordPress.

Twitter Facebook

Useful Links

  • Behind the Scenes
  • Beginner Guides
  • WordPress Hosting
  • WooCommerce Themes
  • MeridianThemes
  • Exclusive WordPress Deals
View All Guides »

Reviews

  • WPEngine 33% OFF
  • Thrive Leads
  • Flywheel 33% OFF
  • Divi Theme 20% OFF
  • Thrive Architect
  • Elegant Themes
Reviews »

Deals

  • InMotion Hosting
  • LifterLMS Coupon
  • LiquidWeb Coupon
  • WPEngine Coupon
  • A2 Hosting
  • FloThemes
More Deals »
© Copyright 2022 WPKube ® All Rights Reserved.
  • About
  • Contact
  • Site Terms
  • Disclosure
  • Privacy Policy