Back to Blog

Beyond Posts & Pages: An Intro to Custom Post Types (CPTs)

ABBy Ajaya BK

Published on July 25, 2024

7 min read
Beyond Posts & Pages: An Intro to Custom Post Types (CPTs)

Introduction: WordPress is More Than Just a Blogging Platform

Out of the box, WordPress comes with two primary content types: Posts and Pages. Posts are for chronological, time-based content (like blog articles), while Pages are for static, hierarchical content (like your 'About' or 'Contact' page). For a simple blog or a basic business website, this is often enough. But what happens when you need to manage a different, distinct type of content? What if you're building a website for a real estate agency and need to manage 'Properties'? Or a movie review site with 'Movies'? Or a personal portfolio with 'Projects'?

You could try to manage these using regular Posts and assigning them a specific category, but this quickly becomes messy and inefficient. The 'Properties' don't belong in your blog feed, and they need their own unique set of data fields, like 'Price,' 'Number of Bedrooms,' and 'Square Footage.' This is where Custom Post Types (CPTs) come in. CPTs are the key to transforming WordPress from a simple blogging platform into a true, flexible Content Management System (CMS).

This guide will explain what Custom Post Types are, why they are so powerful, and how you can easily create and manage them using popular plugins.

What Exactly is a Custom Post Type?

A Custom Post Type is simply a new type of content that you create for your site. When you create a CPT, it gets its own dedicated section in the WordPress admin menu, completely separate from Posts and Pages. This allows for clean content organization and a more intuitive editing experience for you or your clients.

Let's use the example of a 'Portfolio' CPT for a freelance designer. By creating this CPT, you would see a new menu item in your WordPress dashboard called 'Portfolio.' Here, you could add, edit, and manage all your portfolio projects. Each project would be its own entry, just like a blog post, but they would be entirely separate from your blog.

This separation is crucial. It allows you to build custom templates and archives specifically for that content type. You can have a unique design for your portfolio items that is different from your blog posts, and you can create a portfolio archive page (yourdomain.com/portfolio) that lists all your projects without cluttering your main blog feed.

Why Use a Custom Post Type?

  • Content Organization: It's the cleanest way to separate and manage different types of content. It keeps your database structured and your admin dashboard tidy.
  • Custom Fields: CPTs become incredibly powerful when combined with custom fields. For our 'Portfolio' CPT, you could add custom fields for 'Client Name,' 'Project URL,' and 'Services Provided.' For a 'Book' CPT, you could have fields for 'Author,' 'Publisher,' and 'ISBN.' This allows you to store structured data for each post type.
  • Custom Taxonomies: Just like Posts have Categories and Tags, you can create custom taxonomies for your CPTs. For a 'Portfolio' CPT, you could create a 'Service' taxonomy with terms like 'Web Design,' 'Branding,' and 'SEO.' This allows you to sort and filter your portfolio items by the services provided.
  • Custom Templates: You gain fine-grained control over how your content is displayed. You can create a template file in your theme (e.g., single-portfolio.php) that defines the exact layout for all your portfolio items, pulling in the data from your custom fields.

How to Create a Custom Post Type: The Plugin Method

While you can register CPTs by writing PHP code in your functions.php file, the easiest and most recommended method for most users is to use a dedicated plugin. This provides a user-friendly interface and ensures all the necessary options are handled correctly.

Step 1: Install 'Custom Post Type UI' (CPT UI)

This free, immensely popular plugin provides a simple UI for registering and managing custom post types and taxonomies. It doesn't handle the display of the content on the front end, but it's the perfect tool for creating the CPT itself.

  1. Go to Plugins > Add New and search for 'Custom Post Type UI'.
  2. Install and activate the plugin.
  3. You'll see a new 'CPT UI' menu item in your dashboard.

Step 2: Create the Custom Post Type

  1. Go to CPT UI > Add/Edit Post Types.
  2. Fill out the basic settings:
    • Post Type Slug (Plural): This is the key identifier. It must be lowercase, with no spaces. For our example, use portfolio.
    • Plural Label: The plural name for your post type, e.g., Portfolio.
    • Singular Label: The singular name, e.g., Portfolio Item.
  3. Scroll down to the 'Settings' section. This is where you configure the behavior of your CPT. Here are some of the most important settings:
    • Has Archive: Set this to True. This will automatically create an archive page at yourdomain.com/portfolio.
    • Hierarchical: Set to False for content like portfolio items or movies. Set to True if you need parent/child relationships, similar to Pages.
    • Supports: Check the boxes for the features you want this CPT to have. You'll almost always want 'Title,' 'Editor' (for the main content), and 'Thumbnail' (for the featured image). You might also want 'Revisions'.
    • Taxonomies: You can assign existing taxonomies like 'Categories' or 'Tags', but it's often better to create custom ones (see next step).
  4. Click 'Add Post Type'. You will now see your new 'Portfolio' menu item in the WordPress dashboard!

Step 3: Add Custom Fields with 'Advanced Custom Fields' (ACF)

Now that you have your CPT, you need a way to add your structured data (like 'Client Name' and 'Project URL'). The best tool for this is Advanced Custom Fields (ACF).

  1. Install and activate the 'Advanced Custom Fields' plugin.
  2. Go to ACF > Field Groups > Add New.
  3. Give the field group a name, like 'Portfolio Details'.
  4. Click '+ Add Field' to create your custom fields. For each field, you'll give it a Field Label (e.g., 'Client Name') and a Field Type (e.g., Text, URL, Image).
  5. Crucially, in the 'Location' settings box, create a rule that says 'Show this field group if Post Type is equal to Portfolio'. This ensures these custom fields only appear when you are editing a 'Portfolio' item.
  6. Save your field group.

Now, when you go to Portfolio > Add New, you will see your custom fields beautifully integrated below the main content editor.

Step 4: Displaying Your CPTs and Custom Fields

Creating the CPT and fields is the backend part. To display them on the front end, you typically need to create a custom template.

  • Creating an Archive Template: To control the layout of yourdomain.com/portfolio, you can create a file in your child theme called archive-portfolio.php. You can copy the code from your theme's archive.php file as a starting point and modify the loop to display your portfolio items as you wish.
  • Creating a Single Item Template: To control the layout of an individual portfolio item, create a file named single-portfolio.php. Here, you can use ACF's simple PHP functions (like the_field('client_name');) to display the data from your custom fields.

Many modern themes and page builders (like Elementor Pro or Kadence Blocks Pro) have built-in Theme Builders that let you do this visually, without writing any code. You can design a template and assign it to your 'Portfolio' post type, then drag and drop 'Dynamic Content' widgets that pull in your custom field data.

Conclusion

Custom Post Types are a fundamental concept in advanced WordPress development. They allow you to structure your content in a logical, organized, and scalable way. By combining the power of a CPT plugin like CPT UI with a custom fields plugin like ACF, you can build truly bespoke websites for any type of content imaginable, moving far beyond the simple blog and creating a powerful, easy-to-manage Content Management System for your clients.

AB

Written by

Ajaya BK

Ajaya is a WordPress Virtual Assistant specializing in helping businesses set up, fix, and optimize their websites for speed, reliability, and clarity.

More about me