Skip to content
gilltrish.dev

WordPress building blocks · Part 2

What’s a custom post type, and why would I need one?

Beginner9 min read

The 30-second version

A custom post type is a new kind of content, like Recipes or Team members, with its own admin menu, template and web addresses. Use one when entries need different details or layouts from blog posts; use a taxonomy for labels. Plan first: map how your content connects (one-to-one, one-to-many, many-to-many). Make one with ACF, Custom Post Type UI or a little code in a plugin, not your theme. If new pages 404, save Settings → Permalinks. In code, turn on show_in_rest for the block editor.

On this page

The first custom post type I added to a client’s site wasn’t the first one on it. The site already had a few, locations among them, and the client wanted to add their team. Each team member needed to show up on the right location pages and on the blog posts they’d written.

That’s a typical request, and it’s exactly what custom post types are for. This post covers what they are, when you need one (and when you don’t), how to plan them, and three ways to make one. The examples use a made-up shop, example-bakery.com.

WordPress comes with two drawers

Out of the box, WordPress has two drawers for your content. Posts are for things with a date, like news and blog articles. Pages are for things that stay put, like About and Contact.

A custom post type is a new drawer with its own label: “Recipes”, “Locations” or “Team members”. It gets its own spot in the admin menu, its own list of entries and its own web addresses.

Why not just use posts with a category?

You could put every recipe in Posts and give it a “Recipes” category. For a handful of recipes, that’s fine. Once recipes start to look different from blog posts, a post type of their own works better:

  • Different details. A recipe needs prep time, ingredients and a photo. A blog post doesn’t. A post type can have its own fields (that’s the next post in this series).
  • Different layout. Recipes can have their own template, so they look like recipes, not blog posts.
  • A cleaner admin. Editors get a “Recipes” menu item. They can’t accidentally publish a recipe as a news post.
  • Cleaner web addresses. example-bakery.com/recipes/sourdough/ instead of example-bakery.com/2026/11/sourdough/.
  • A list page for free. WordPress can make an archive at /recipes/ that lists every recipe.

What makes a good post type?

A good post type is a kind of thing you’ll have lots of, where every entry has the same shape. For the bakery, that could be:

  • Recipes: title, photo, prep time, ingredients, method.
  • Locations: address, opening hours, map.
  • Team members: name, photo, job title, which shop they work at.
  • Events: date, time, place, how to book.

Some things look like they need a post type but don’t:

  • A one-off page, like the bakery’s story. There’s only one, so a normal page is fine.
  • A label, like “Gluten-free” or “Bread”. That’s for sorting things, which is what taxonomies do.

Taxonomies are the labels inside the drawer

Once you have a Recipes drawer, you’ll want to sort what’s in it. Taxonomies are the labels you stick on things so you can find them again.

WordPress comes with two for posts: categories (organised, can have parents and children) and tags (loose keywords). You can make your own too, like a “Recipe type” taxonomy with Bread, Cakes and Pastries. Then /recipe-type/bread/ lists every bread recipe.

How the pieces fit together

  1. Post type: RecipeThe drawer that holds every recipe
  2. FieldsPrep time, ingredients, photo (next post)
  3. Taxonomy: Recipe typeBread, Cakes, Pastries
  4. TemplatesOne recipe page, plus the /recipes/ list

Plan first: how does your content connect?

This is the step that’s easiest to skip, and it matters most. Before you build anything, work out how your post types relate to each other. Things are much easier to change on paper than once there’s real content in them.

There are three kinds of relationship to look out for:

  • One-to-one: each thing has exactly one of the other. Each location has one manager, and each manager runs one location. These are rare between post types. Often it’s simpler as a field.
  • One-to-many: one thing has lots of the other, but not the other way round. One location has many team members, and each team member works at one location.
  • Many-to-many: lots on both sides. A team member covers several locations, and each location has several team members. A recipe can appear in several events, and an event can feature several recipes.

That team members request from the start of this post had two of these at once: team members to locations, and team members to blog posts, both many-to-many. Knowing that up front decides which kind of field you use, and which screen editors make the connection from.

Planning a new post type

  1. List your contentRecipes, locations, team members…
  2. Sort or store?Labels → taxonomy. Things with pages → post type
  3. Map the relationshipsOne-to-one, one-to-many or many-to-many?
  4. Pick the editing sideWhich screen do editors make the link on?
  5. Build itPost types, then taxonomies, then fields

You don’t need special software for this. Boxes and arrows on paper work fine. Draw each post type as a box, draw a line between things that connect, and write “1” or “many” at each end of the line.

Three ways to make one

Step 1:With ACF

Advanced Custom Fields (or its fork, Secure Custom Fields; more on that in the next post) has had a screen for making post types and taxonomies since version 6.1, including in the free version. Go to ACF → Post Types → Add New, fill in the singular and plural names, and save. It’s handy if you’re already using ACF for fields, because everything lives in one place.

Step 2:With Custom Post Type UI

Custom Post Type UI is a free plugin that does one job: making post types and taxonomies through a form in the admin. Go to CPT UI → Add/Edit Post Types. It’s well kept and widely used.

Step 3:With a little code

You can register a post type yourself in a small custom plugin, like the one in the plugins post. No extra plugin to keep updated, and the setup lives in a file you can keep in version control. There’s an example below.

Some page builders and themes have their own post type tools too. They work, but your content then depends on that tool sticking around.

On an existing site, use what’s already there

I usually reach for ACF or code. But if a site already has its post types set up in CPT UI, I add the new one in CPT UI too. If they’re in code, I use code. The next developer shouldn’t have to search in two places to find where something is set up.

The code version

Here’s a complete little plugin that adds Recipes and a Recipe type taxonomy. Save it as a file in its own folder in wp-content/plugins, then turn it on under Plugins.

wp-content/plugins/example-bakery-recipes/example-bakery-recipes.php· PHP
<?php
/**
 * Plugin Name: Example Bakery Recipes
 * Description: Adds a Recipes post type and a Recipe type taxonomy.
 */

// Stop anyone loading this file directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function bakery_register_recipes() {
	register_post_type( 'recipe', array(
		'labels'       => array(
			'name'          => 'Recipes',
			'singular_name' => 'Recipe',
			'add_new_item'  => 'Add new recipe',
		),
		'public'       => true,  // Show it in the admin and on the site.
		'has_archive'  => true,  // Make a list page at /recipes/.
		'show_in_rest' => true,  // Use the block editor. Off by default!
		'menu_icon'    => 'dashicons-carrot',
		'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'rewrite'      => array( 'slug' => 'recipes' ), // /recipes/sourdough/
	) );

	register_taxonomy( 'recipe_type', 'recipe', array(
		'labels'            => array(
			'name'          => 'Recipe types',
			'singular_name' => 'Recipe type',
		),
		'hierarchical'      => true, // Works like categories, with checkboxes.
		'show_in_rest'      => true, // Show it in the block editor sidebar.
		'show_admin_column' => true, // Add a column to the Recipes list.
		'rewrite'           => array( 'slug' => 'recipe-type' ),
	) );
}
add_action( 'init', 'bakery_register_recipes' );

// Refresh the permalinks once, when the plugin is turned on.
function bakery_recipes_activate() {
	bakery_register_recipes();
	flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'bakery_recipes_activate' );

A few things worth knowing about that code:

  • public, has_archive and show_in_rest are all off unless you turn them on. Leave them out and your post type is hidden, has no list page and opens in the old editor.
  • supports decides which boxes appear on the edit screen. Leave out thumbnail and there’s no featured image.
  • init is the hook WordPress wants post types registered on. Earlier is too early.

Showing it on the site

WordPress picks a template for each page by looking for the most specific file first. For a recipe, a classic theme looks for single-recipe.php, then falls back to single.php. For the list page, it looks for archive-recipe.php, then archive.php.

So your recipes will show up straight away using your normal post layout. When you want them to look different, copy single.php to single-recipe.php and change it. In a block theme, go to Appearance → Editor → Templates, add a new template and pick your post type from the list.

Gotchas

Put post types in a plugin, not your theme

It’s tempting to paste the code into your theme’s functions.php. But if you ever change themes, the post type goes with it. Your recipes vanish from the admin and their pages stop working.

They aren’t deleted, they’re still in the database, but it’s a scary afternoon. A plugin keeps your content separate from how it looks.

New post type, 404 pages

You’ve made Recipes, added one, clicked View… and got “Page not found”. WordPress keeps a list of web address patterns, and it doesn’t know about /recipes/ yet.

The fix: go to Settings → Permalinks and click Save Changes. You don’t need to change anything. Saving rebuilds the list. (The activation code in the example does this for you.)

No block editor? You probably didn’t break anything

I’ve had a new post type open in the old classic editor and thought I’d broken something. I hadn’t. show_in_rest is off by default in code, and the block editor needs it. Set it to true and refresh.

Choose the name carefully, because it’s hard to change

The post type’s key (recipe in the example) is stored with every entry. Rename it later and WordPress won’t connect your existing recipes to the new name, so they disappear from the admin. Getting them back means updating the database.

  • Use something short and singular, like recipe or team_member. The limit is 20 characters, using lowercase letters, numbers, dashes and underscores.
  • Don’t use names WordPress already uses, like post, page, attachment, revision, action, author, order or theme.
  • The labels (“Recipes”, “Add new recipe”) are safe to change any time. It’s only the key that sticks.

As with plugins, try a new post type on a local copy of the site before you add it to the live one. If you don’t have a local copy yet, here’s how to make one.

What I’d tell past me

Understand the flow first. Before you make a single post type, sketch how your content connects and whether each link is one-to-one, one-to-many or many-to-many. The building takes minutes. Undoing the wrong structure once there’s real content takes much longer.

Next in this series: custom fields, where each recipe gets proper boxes for prep time, ingredients and a photo, and team members get linked to their locations.