WordPress Custom Post Types Tutorial: A Complete Guide for 2026 by Jackober.com

WordPress Custom Post Types Tutorial: A Complete Guide for 2026

Register a WordPress custom post type with code, add a taxonomy and custom fields, display it in classic and block themes, and know when a plugin is the better choice.

WordPress ships with posts and pages, but many sites hold content that is neither: recipes, events, team members, portfolio projects, or testimonials. Custom post types (CPTs) let you give that content its own section in the dashboard, its own URLs, its own fields, and its own templates.

This tutorial shows how to register a custom post type with code, add a taxonomy and custom fields, display the content on the front end in classic and block themes, and when a plugin is the better choice in 2026.

The Short Answer

TaskHow
Register the post typeregister_post_type() on the init hook, in a plugin
Make it work in the block editor'show_in_rest' => true
Give it archive and single URLs'public' => true, 'has_archive' => true, a rewrite slug
Group itemsregister_taxonomy()
Store extra dataregister_post_meta(), or a fields plugin such as ACF
Fix 404s after registeringFlush rewrite rules (save Settings > Permalinks)
No-code optionCustom Post Type UI, or ACF’s post type tools

What Is a Custom Post Type?

Everything in WordPress’s main content table is a “post” of some type. Posts, pages, attachments, revisions, and navigation menus are all built-in post types. A custom post type is one you add yourself, such as recipe or event.

WordPress dashboard with a custom post type menu in the admin sidebar
A registered custom post type gets its own menu in the dashboard sidebar.

Good reasons to create one:

  • The content has a different structure. A recipe has cook time and ingredients. A blog post does not.
  • It needs its own URLs and archive. For example, /recipes/ and /recipes/banana-bread/.
  • Editors need a separate menu. A dedicated “Recipes” menu is clearer than a “Recipes” category mixed in with news posts.

If the content is just another kind of article, a category or tag is usually enough. Don’t create a post type you don’t need.

Register a Custom Post Type With Code

Put the code in a small custom plugin (or a must-use plugin), not in your theme’s functions.php. Content stored in a post type should not disappear from the dashboard when you switch themes.

Create a file such as wp-content/plugins/mysite-recipes/mysite-recipes.php:

<?php
/**
 * Plugin Name: My Site Recipes
 * Description: Registers the Recipe post type.
 */

function mysite_register_recipe_post_type() {
    $labels = array(
        'name'          => 'Recipes',
        'singular_name' => 'Recipe',
        'add_new_item'  => 'Add New Recipe',
        'edit_item'     => 'Edit Recipe',
        'all_items'     => 'All Recipes',
        'search_items'  => 'Search Recipes',
        'not_found'     => 'No recipes found',
    );

    register_post_type( 'mysite_recipe', array(
        'labels'       => $labels,
        'public'       => true,
        'has_archive'  => true,
        'show_in_rest' => true,
        'menu_icon'    => 'dashicons-carrot',
        'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ),
        'rewrite'      => array( 'slug' => 'recipes' ),
    ) );
}
add_action( 'init', 'mysite_register_recipe_post_type' );

function mysite_recipes_activate() {
    mysite_register_recipe_post_type();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'mysite_recipes_activate' );

Activate the plugin and a Recipes menu appears in the dashboard.

What the main arguments do

  • The key (mysite_recipe). At most 20 characters, lowercase letters, numbers, dashes, and underscores only. A prefix avoids clashes with other plugins. Don’t change it later, because existing items are stored under this key.
  • public. Makes the post type visible in the dashboard and on the front end.
  • has_archive. Creates an archive page, here at /recipes/.
  • show_in_rest. Makes the post type available in the REST API and therefore in the block editor. Without it, editors get the classic editor.
  • supports. Chooses the editing features. custom-fields is needed if you want registered meta in the REST API and block editor.
  • rewrite. Sets the URL slug. Use a plural, readable word.
  • menu_icon. Any Dashicons name, or a URL to an icon.

Register post types on init, not earlier. The activation hook registers the type and then flushes rewrite rules once, so the new URLs work straight away. Never call flush_rewrite_rules() on every page load, because it’s slow.

Add a Taxonomy

A taxonomy groups items in a post type, the way categories group posts. This adds a hierarchical “Difficulty” taxonomy to recipes:

function mysite_register_difficulty_taxonomy() {
    register_taxonomy( 'mysite_difficulty', 'mysite_recipe', array(
        'labels'            => array(
            'name'          => 'Difficulty Levels',
            'singular_name' => 'Difficulty Level',
        ),
        'hierarchical'      => true,
        'show_in_rest'      => true,
        'show_admin_column' => true,
        'rewrite'           => array( 'slug' => 'difficulty' ),
    ) );
}
add_action( 'init', 'mysite_register_difficulty_taxonomy' );

Set hierarchical to true for category-style checkboxes, or false for tag-style terms. show_in_rest is needed for the taxonomy panel to appear in the block editor. Our guide to creating WordPress custom taxonomies covers this in more depth.

Add Custom Fields

For simple values, register the meta key so WordPress knows its type, sanitizes it, and exposes it to the block editor:

function mysite_register_recipe_meta() {
    register_post_meta( 'mysite_recipe', 'mysite_cook_time', array(
        'type'              => 'integer',
        'description'       => 'Cook time in minutes',
        'single'            => true,
        'show_in_rest'      => true,
        'sanitize_callback' => 'absint',
        'auth_callback'     => function() {
            return current_user_can( 'edit_posts' );
        },
    ) );
}
add_action( 'init', 'mysite_register_recipe_meta' );

Registered meta has no visible input box on its own. You either build one (a block editor panel or a classic meta box with a nonce and capability check), or use a fields plugin. For most sites, a plugin such as Advanced Custom Fields (ACF) or Meta Box is faster and safer. It handles the input UI, validation, and saving.

Recipe custom post type edit screen with custom fields and a difficulty taxonomy
A recipe post type with custom fields (image, prep time, cook time) and a difficulty taxonomy in the sidebar.

Display Custom Post Types on the Front End

Templates

WordPress picks templates using the template hierarchy. For the mysite_recipe post type:

  • Classic themes: single-mysite_recipe.php for one recipe, and archive-mysite_recipe.php for the archive. If they don’t exist, WordPress falls back to single.php, archive.php, and finally index.php.
  • Block themes: create single-mysite_recipe.html and archive-mysite_recipe.html templates, most easily in Appearance > Editor > Templates.

If you edit a classic theme, put template files in a child theme so updates don’t overwrite them.

Chart of the WordPress template hierarchy
The WordPress template hierarchy, showing which template file WordPress tries first for each kind of page.

Custom queries

To list recipes anywhere in a classic theme, use WP_Query and reset post data afterwards:

$recipes = new WP_Query( array(
    'post_type'      => 'mysite_recipe',
    'posts_per_page' => 6,
) );

if ( $recipes->have_posts() ) {
    while ( $recipes->have_posts() ) {
        $recipes->the_post();
        the_title( '<h3><a href="' . esc_url( get_permalink() ) . '">', '</a></h3>' );
    }
    wp_reset_postdata();
}

Block editor

In block themes or block-based pages, add a Query Loop block and choose your post type in its settings. The post type only appears there if show_in_rest is true.

REST API

With show_in_rest on, items are available at /wp-json/wp/v2/mysite_recipe by default. You can change that path with the rest_base argument.

The Plugin Route

If you’d rather not write code:

  • Custom Post Type UI registers post types and taxonomies from a settings screen.
  • Advanced Custom Fields (version 6.1 and later) can register post types and taxonomies as well as field groups, so one plugin covers the whole setup.

The trade-off is that the post type depends on that plugin staying active. Both plugins can export PHP code, so you can move the registration into your own plugin later.

Common Problems

  • 404 on new CPT pages. Rewrite rules haven’t been refreshed. Go to Settings > Permalinks and click Save Changes.
  • The block editor doesn’t appear. show_in_rest is missing or false, or editor isn’t in supports.
  • The taxonomy panel is missing in the editor. The taxonomy needs show_in_rest => true.
  • The archive page shows nothing. has_archive is off, or a page with the same slug as the archive is overriding it.
  • Items vanished after a theme switch. The post type was registered in the old theme. The content is still in the database. Register the same key in a plugin and it comes back.
  • Custom fields don’t save. Check the field names, the sanitize callback, and that the user has permission to edit.

Common Mistakes

  • No prefix on the key. A generic key like event can clash with a plugin.
  • Changing the key on a live site. Existing content stays under the old key and disappears from the dashboard.
  • Registering post types in the theme. Use a plugin so content survives a redesign.
  • Flushing rewrite rules on every request. Only flush on activation, deactivation, or after changing slugs.
  • Creating a post type that should be a category. If the content shares the same fields as posts, use a taxonomy instead.

FAQ

Are custom post types good for SEO?

They help when they give distinct content clean URLs, focused archives, and the right structured data. They don’t help by themselves. SEO plugins like Yoast let you set titles and indexing per post type. Our schema markup guide shows how to describe content such as recipes and events.

Should I put the code in functions.php?

It works, but a small plugin is better because the post type stays registered if you change themes.

What’s the difference between a custom post type and a taxonomy?

A post type is a kind of content, such as recipes. A taxonomy groups items within it, such as difficulty levels or cuisines.

Can I convert existing posts into a custom post type?

Yes. A plugin such as Post Type Switcher can change the post type of existing items. Back up first and set up redirects if the URLs change.

Do custom post types slow WordPress down?

Not in any meaningful way. Slowdowns usually come from heavy meta queries on large sites, which caching and well-planned taxonomies help with.

The Bottom Line

Register custom post types in a plugin, with a prefixed key, show_in_rest turned on, and a clear URL slug. Add taxonomies for grouping and registered meta or a fields plugin for structured data, then use templates or the Query Loop block to display them. If you don’t want to write code, Custom Post Type UI or ACF gets you the same result from the dashboard.

Sources & Further Reading

Articles are editorially reviewed by Jackober and factual claims are checked against cited sources.

Leave a Reply

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

You May Also Like