WordPress Custom Post Types: Complete Developer Tutorial

How to register a custom post type, meta with revisions_enabled, show_in_rest, block templates, capabilities and rewrite flushing, checked on WordPress 7.1.4.

Stack of three post revisions showing the acme_client meta value changing, beside the title Custom Post Types

To keep post meta in revisions for a custom post type, pass 'revisions_enabled' => true in the arguments of register_post_meta(), and make sure the post type lists revisions in its supports array. The argument arrived in WordPress 6.4 and defaults to false. If the post type does not support revisions when the meta key is registered, core logs a _doing_it_wrong notice and refuses to register the key at all.

That one rule is behind most of the searches that send people to this page. The rest of this tutorial walks the whole job in order: registering the type, getting its URLs to work, exposing it to the block editor and REST API, adding meta that survives revisions, setting capabilities, and querying the result. We read every function and argument against the WordPress 7.1.4 source and the developer.wordpress.org reference, and the code snippets passed php -l on PHP 8.5. Checked on 15 Nov 2026.

We did not run the snippets end to end on a live site for this refresh. Every behaviour claimed below comes from the core source or an official page we link, so if you hit a difference on your own install, trust your install and tell us.

What is a custom post type?

A post type is a label stored in the post_type column of the wp_posts table. Core ships with post, page, attachment, revision, nav_menu_item, custom_css, customize_changeset, oembed_cache, user_request, wp_block, wp_template, wp_template_part, wp_global_styles, wp_navigation, wp_font_family and wp_font_face. A custom post type is one you register yourself, with its own labels, admin menu entry, URLs, capabilities and editor behaviour.

You reach for one when the content is not a blog post and not a page: projects, events, listings, courses, case studies. The data lives in the same tables as everything else, so search, the REST API, feeds, the media library and the export tool all work with it from the first line of code.

What is the WordPress post object?

When you load any of these items, WordPress hands you a WP_Post object. It has the fields from the wp_posts row (ID, post_title, post_content, post_status, post_type, post_parent and so on). Custom fields are not on the object. You read them with get_post_meta(), which is why registering meta properly matters later in this guide.

When a custom post type is the wrong tool

Skip it when the data is really a list of options (use settings), when you need relational queries across thousands of rows (a custom table may fit better, see our $wpdb best practices guide), or when a category and a page template would do. A new post type is a long-term commitment. Deleting the plugin that registers it does not delete the rows, it only hides them.

How do you register a custom post type?

Call register_post_type() on the init hook. Not earlier, not in a template file. The first argument is the key: lowercase letters, numbers, dashes and underscores, at most 20 characters. Core runs it through sanitize_key() and returns a WP_Error with the code post_type_length_invalid if it is empty or too long. Prefix it with your plugin name (acme_project, not project) so another plugin cannot claim the same key.

Here is a plugin file that registers a Projects type with the arguments most real projects need. Checked on 15 Nov 2026 against WordPress 7.1.4.

<?php
/**
 * Plugin Name: Acme Projects
 */

defined( 'ABSPATH' ) || exit;

function acme_register_project_post_type() {
	register_post_type(
		'acme_project',
		array(
			'labels'        => array(
				'name'          => __( 'Projects', 'acme-projects' ),
				'singular_name' => __( 'Project', 'acme-projects' ),
				'add_new_item'  => __( 'Add New Project', 'acme-projects' ),
				'edit_item'     => __( 'Edit Project', 'acme-projects' ),
				'view_item'     => __( 'View Project', 'acme-projects' ),
				'all_items'     => __( 'All Projects', 'acme-projects' ),
				'search_items'  => __( 'Search Projects', 'acme-projects' ),
				'not_found'     => __( 'No projects found.', 'acme-projects' ),
			),
			'public'        => true,
			'has_archive'   => 'projects',
			'rewrite'       => array(
				'slug'       => 'projects',
				'with_front' => false,
			),
			'menu_icon'     => 'dashicons-portfolio',
			'show_in_rest'  => true,
			'rest_base'     => 'projects',
			'supports'      => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'revisions' ),
			'template'      => array(
				array( 'core/paragraph', array( 'placeholder' => __( 'What was the brief?', 'acme-projects' ) ) ),
				array( 'core/heading', array( 'level' => 2, 'content' => __( 'Result', 'acme-projects' ) ) ),
				array( 'core/paragraph' ),
			),
			'template_lock' => false,
		)
	);
}
add_action( 'init', 'acme_register_project_post_type' );

Two details in that snippet cost people time. First, if you only pass name and singular_name, WordPress fills the other labels from the built-in Post labels, so your admin screens still say “Add New Post”. Set add_new_item, edit_item and the rest. Second, supports defaults to title and editor only. Anything else, including revisions, has to be listed.

Which register_post_type arguments matter most?

The full list is long. These are the ones that change behaviour you will notice, with the defaults taken from the 7.1.4 source.

Argument

Default

What it does

public

false

Sets the defaults for show_ui, publicly_queryable, exclude_from_search and show_in_nav_menus. Each can be overridden on its own.

show_in_rest

false

Adds REST routes and, together with editor support, turns on the block editor for this type.

rest_base

the post type key

Changes the route segment, so /wp/v2/projects instead of /wp/v2/acme_project.

supports

title, editor

Core features: excerpt, thumbnail, custom-fields, revisions, author, comments, page-attributes and more.

has_archive

false

True or a string slug. Creates the archive URL and its rewrite rules.

rewrite

true, using the key as slug

Pass an array to set slug, with_front, feeds and pages. False turns pretty permalinks off for the type.

capability_type

post

Base string used to build the capability names. Can be an array of singular and plural.

map_meta_cap

false (true only in a back-compat case)

Whether core maps edit_post, delete_post and read_post to the primitive capabilities.

template and template_lock

empty and false

Default blocks for a new post, and whether editors can change them. Added in 5.0.

delete_with_user

null

If unset, posts are trashed on user deletion only when the type supports author.

Source: the argument documentation in wp-includes/post.php and the defaults in class-wp-post-type.php, WordPress 7.1.4, checked on 15 Nov 2026. The register_post_type reference carries the same list.

Why does my custom post type return a 404?

Because WordPress has not learned your new URLs yet. Registering a type with public true and a rewrite setting adds rewrite rules, but the rules are cached in the rewrite_rules option. Until that option is rebuilt, /projects/my-first-project/ falls through to a 404.

The quick fix on a dev site is to open Settings, then Permalinks, and press Save. That rebuilds the rules. For code you ship, flush once on activation:

<?php
register_activation_hook(
	__FILE__,
	static function () {
		// Activation runs after init, so register the type first, then flush.
		acme_register_project_post_type();
		flush_rewrite_rules();
	}
);

register_deactivation_hook(
	__FILE__,
	static function () {
		unregister_post_type( 'acme_project' );
		flush_rewrite_rules();
	}
);

Order matters in the activation callback. The plugin is activated from an admin request that has already passed init, so your init callback has not run for the new plugin yet. Register the type by hand, then flush, or the saved rules will not contain it. On deactivation, unregister first for the same reason.

Never call flush_rewrite_rules() on every init. The reference page calls it an expensive operation, and a hard flush also tries to write .htaccess on Apache. It takes $hard as its only argument, default true, and passing false updates the stored rules without touching the server config. If a type 404s after an update to your plugin, store a version number and flush once when it changes. Our guide to upgrade paths and activation hooks covers that pattern.

Other causes of a 404 worth ruling out: a page or post with the same slug as your rewrite slug, a public value of false, and a rewrite slug that collides with another type or taxonomy.

How do you enable the block editor and REST API?

Set show_in_rest to true and keep editor in supports. Without show_in_rest the type opens in the classic editor and has no REST routes. The core docblock says it directly: set it to true for the post type to be available in the block editor.

Once it is on, the type appears under /wp/v2/<rest_base>. Public reads need no authentication for published posts, so treat show_in_rest as publishing your data. If a type should stay private, set public to false and show_ui to true, and rely on capabilities. For authenticated writes see our REST API authentication guide, and for routes of your own, custom REST endpoints done right.

The controller class, namespace and base are all adjustable (rest_controller_class, rest_namespace, rest_base), but change them only with a reason. Block editor code and third-party clients expect the defaults.

Taxonomies follow the same rule. A taxonomy needs show_in_rest true to show its panel in the block editor and to be assignable through the API:

<?php
add_action(
	'init',
	static function () {
		register_taxonomy(
			'acme_service',
			'acme_project',
			array(
				'labels'            => array(
					'name'          => __( 'Services', 'acme-projects' ),
					'singular_name' => __( 'Service', 'acme-projects' ),
				),
				'hierarchical'      => true,
				'show_in_rest'      => true,
				'show_admin_column' => true,
				'rewrite'           => array( 'slug' => 'services' ),
			)
		);
	}
);

A taxonomy key can be up to 32 characters. That limit is separate from the 20 for post types.

How do you register post meta for a custom post type?

Use register_post_meta( $post_type, $meta_key, $args ). It is a thin wrapper: it sets object_subtype to your post type and calls register_meta( 'post', ... ). Passing an empty string for the post type registers the key for every post type. Registering is not required to save meta, but it is what gives you REST access, typed values, sanitising, a default and revision support.

The arguments that matter, all checked in register_meta() in 7.1.4:

Argument

Notes

type

string, boolean, integer, number, array or object. Default string.

single

One value per post (true) or a list of values (false, the default).

default

Returned by get_post_meta() when nothing is saved. For non-single keys it is wrapped in an array.

show_in_rest

True, or an array with schema and prepare_callback. Needs the post type to support custom-fields.

sanitize_callback

Runs on every save through the core filter. Use it, REST does not replace it.

auth_callback

Capability check for edit, add and delete. Without one, keys starting with an underscore are blocked and the rest are allowed.

label

Added in 6.7. A human-readable name used by editor UI.

revisions_enabled

Added in 6.4. Copies the value into revisions. Post object type only.

<?php
function acme_register_project_meta() {
	register_post_meta(
		'acme_project',
		'acme_client',
		array(
			'type'              => 'string',
			'single'            => true,
			'default'           => '',
			'label'             => __( 'Client', 'acme-projects' ),
			'description'       => __( 'Client name shown on the project page.', 'acme-projects' ),
			'sanitize_callback' => 'sanitize_text_field',
			'auth_callback'     => static function ( $allowed, $meta_key, $post_id ) {
				return current_user_can( 'edit_post', $post_id );
			},
			'show_in_rest'      => true,
			'revisions_enabled' => true,
		)
	);

	register_post_meta(
		'acme_project',
		'acme_gallery_ids',
		array(
			'type'         => 'array',
			'single'       => true,
			'show_in_rest' => array(
				'schema' => array(
					'type'  => 'array',
					'items' => array( 'type' => 'integer' ),
				),
			),
		)
	);
}
// Priority 11: the post type must already support 'revisions' when this runs.
add_action( 'init', 'acme_register_project_meta', 11 );

Four gotchas sit in that snippet and the table.

  • The REST meta property only exists when the post type supports custom-fields. In the posts controller schema, the meta field is added in the custom-fields case. Leave the support out and your registered keys vanish from responses.
  • Array and object meta need a schema. For an array type with show_in_rest, core requires show_in_rest['schema']['items']. Without it, register_meta() logs a notice and returns false.
  • A key that starts with an underscore is protected. is_protected_meta() makes the default auth_callback return false for it, so REST writes fail until you supply your own callback.
  • When single is false, the REST schema is wrapped as an array of your schema. Clients send a list, not a bare value.

Block themes can show registered meta without PHP. The core/post-meta block bindings source reads a key for the current post, but only if the key is registered with show_in_rest and is not protected. We cover binding below.

What does register_post_meta revisions_enabled do?

It tells core to store that meta key on every revision and to restore it when someone restores a revision. Before 6.4 the revision screen only tracked title, content and excerpt, so a restore left your custom fields at their latest value.

The mechanics, from wp-includes/revision.php:

  1. wp_post_revision_meta_keys( $post_type ) merges the keys registered for all posts and the keys registered for your type, then keeps those with revisions_enabled true. The result runs through the wp_post_revision_meta_keys filter.
  2. When a revision is saved, wp_save_revisioned_meta_fields() copies each listed key from the post to the revision.
  3. A change to one of those meta values counts as a change when core decides whether to save a new revision, even if the title and content are identical. The check is hooked on wp_save_post_revision_post_has_changed.
  4. On restore, wp_restore_post_revision_meta() deletes the post’s current values for those keys and copies the revision’s values back. It is hooked on wp_restore_post_revision.
  5. Autosaves and previews use the same list, so a preview shows unsaved meta from the autosave.

The requirements, all enforced at registration:

  • The object type must be post. For comments, terms or users, revisions_enabled logs a _doing_it_wrong notice and registration returns false.
  • If you pass a post type as the subtype, that type must already support revisions. Register the type first, which is why the snippet above runs the meta registration at priority 11.
  • revisions_enabled only applies to keys you register. For a key you do not control, add it with the wp_post_revision_meta_keys filter.
<?php
// Core footnotes use the same mechanism. To revision a key you do not register yourself:
add_filter(
	'wp_post_revision_meta_keys',
	static function ( $keys, $post_type ) {
		if ( 'acme_project' === $post_type && ! in_array( 'acme_budget_note', $keys, true ) ) {
			$keys[] = 'acme_budget_note';
		}
		return $keys;
	},
	10,
	2
);

// Read the saved copies while debugging.
$revisions = wp_get_post_revisions( $post_id );
foreach ( $revisions as $revision ) {
	echo $revision->ID, ' ', get_post_meta( $revision->ID, 'acme_client', true ), "\n";
}

Core uses this itself. The footnotes meta key is registered with show_in_rest true, single true and revisions_enabled true in wp-includes/blocks/footnotes.php. The 6.4 dev note on post meta revisions (published 24 Oct 2023) describes the design and warns that revisions are now created on wp_after_insert_post, after meta is saved, instead of post_updated. One more note from it: the example filter in that post appends a different key than the one it tests, so copy the pattern, not the example.

Two limits to keep in mind. Revisioned meta is stored as rows on the revision post, so a direct meta_query or SQL query over wp_postmeta can now return revision rows unless you filter by post type or post_parent. And revision storage grows with every save. WP_POST_REVISIONS (default true, meaning keep all) caps it, and the wp_revisions_to_keep filter can do the same per post type. A supports array without revisions turns the whole system off for the type.

How do block templates work for a custom post type?

There are two separate things called templates here, and mixing them up causes confusion.

The editor template for new posts

The template argument is an array of blocks that every new post starts with. Each item is a block name plus optional attributes, with inner blocks as a third element. The snippet above starts each project with a paragraph, a “Result” heading and an empty paragraph. This has been available since WordPress 5.0.

template_lock controls how much editors can change it:

Value

Effect

false (default)

No lock. Editors can change anything.

'insert'

Blocks can be moved but not added or removed.

'contentOnly'

Only the content inside existing blocks can be edited.

'all'

No adding, moving or deleting.

The template only applies to new posts. Existing posts keep the content they have. The lock is also an editor feature, so it does not stop a REST write or a code call from changing content.

The front-end template for the type

In a block theme, a file named templates/single-acme_project.html renders one project and templates/archive-acme_project.html renders the archive. The names come from the standard template hierarchy: single-{post_type} and archive-{post_type}, which core builds in wp-includes/template.php. Classic themes use the .php equivalents.

Since WordPress 6.7, a plugin can ship a template without touching the theme by calling register_block_template(). The name must be lowercase and carry a namespace, in the form my-plugin//my-template, and the arguments are title, description, content, post_types and plugin. We read the registry class but did not test overriding a theme’s own single template, so check the order on your site before you rely on it.

To show meta in a template, bind a block attribute to it. In 7.1 the supported attributes are content on paragraph and heading (and list item, new in 7.1), url, alt, title, id and caption on image, and url, text, linkTarget and rel on button. In the code editor the binding looks like this:

{
  "metadata": {
    "bindings": {
      "content": {
        "source": "core/post-meta",
        "args": { "key": "acme_client" }
      }
    }
  }
}

That JSON goes in the comment delimiter of a paragraph block. It only returns a value when the post is viewable by the visitor, the key is not protected, and the key is registered with show_in_rest for that post type. If the bound text is empty, check those three first.

How do capabilities and map_meta_cap work?

By default a custom type uses the capabilities of posts: edit_posts, publish_posts and the rest. Any editor can manage your type the same way they manage blog posts. That is fine for many sites.

To give the type its own permissions, set capability_type to a singular and plural pair and set map_meta_cap to true. With acme_project and acme_projects, core builds names such as edit_acme_projects, edit_others_acme_projects and publish_acme_projects. You can also pass an explicit capabilities array.

Two points trip people up. map_meta_cap defaults to false for custom capability types. The only case where core turns it on for you is a base of post or page with no custom capabilities. Leave it off and calls like current_user_can( 'edit_post', $id ) do not translate to your new primitives. Second, no role has the new capabilities, administrators included. The type disappears from the menu until you grant them:

<?php
// In the register_post_type() args:
//   'capability_type' => array( 'acme_project', 'acme_projects' ),
//   'map_meta_cap'    => true,

function acme_grant_project_caps() {
	$role = get_role( 'administrator' );
	$type = get_post_type_object( 'acme_project' );
	if ( ! $role || ! $type ) {
		return;
	}

	$keys = array(
		'edit_posts',
		'edit_others_posts',
		'edit_private_posts',
		'edit_published_posts',
		'publish_posts',
		'read_private_posts',
		'delete_posts',
		'delete_others_posts',
		'delete_private_posts',
		'delete_published_posts',
	);

	foreach ( $keys as $key ) {
		$role->add_cap( $type->cap->$key );
	}
}
// Call it once from the activation hook, after the type is registered.

Run that once, on activation or in an upgrade routine. add_cap() writes to the roles option, so calling it on every request is wasted work. Taxonomies add another wrinkle: the default assign_terms capability is edit_posts, so a role that can edit your type but not posts cannot tag it until you set the taxonomy capabilities too.

A Meta Box support thread from 2019 to 2022 shows the same story in the wild: capabilities not mapped until map_meta_cap was added, then a menu that stayed hidden until the role had the matching plural names. Details are in the common mistakes list below.

Should I use meta boxes or registered meta?

For a block editor type, registered meta plus a sidebar panel or block binding is the modern route. Classic meta boxes still work, and they are the quickest way to add a few fields when you have no JavaScript build. Our post on meta boxes in the WordPress 7 editor covers how they behave now.

If you use a meta box, do the three checks every time: nonce, capability, autosave. The hook add_meta_boxes_{post_type} and the save_post_{post_type} action both take the type in their name, which keeps the code from running for other types.

<?php
add_action(
	'add_meta_boxes_acme_project',
	static function () {
		add_meta_box( 'acme_project_details', __( 'Project details', 'acme-projects' ), 'acme_render_details_box', 'acme_project', 'side' );
	}
);

function acme_render_details_box( $post ) {
	wp_nonce_field( 'acme_save_details', 'acme_details_nonce' );
	printf(
		'<p><label for="acme_client">%s</label><input type="text" class="widefat" id="acme_client" name="acme_client" value="%s"></p>',
		esc_html__( 'Client', 'acme-projects' ),
		esc_attr( get_post_meta( $post->ID, 'acme_client', true ) )
	);
}

add_action(
	'save_post_acme_project',
	static function ( $post_id ) {
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
			return;
		}
		if ( ! isset( $_POST['acme_details_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['acme_details_nonce'] ) ), 'acme_save_details' ) ) {
			return;
		}
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return;
		}
		if ( isset( $_POST['acme_client'] ) ) {
			update_post_meta( $post_id, 'acme_client', sanitize_text_field( wp_unslash( $_POST['acme_client'] ) ) );
		}
	}
);

Note that the field above writes the same key we registered with revisions_enabled. Revision tracking sits on the meta key, not on how the value got saved, so both paths are covered.

ACF or native meta, which should you use?

Native meta is the right default for a plugin you distribute and for a handful of simple fields. Advanced Custom Fields earns its place when non-developers need to design the field groups, or you need field types that are slow to hand-build.

We rechecked the ACF facts on 15 Nov 2026. The WordPress.org listing shows version 6.8.11, updated 2 Nov 2026, 2 million or more active installs, tested up to WordPress 7.1.4 and requiring PHP 7.4. ACF’s own pages list the repeater, flexible content, gallery and clone fields, options pages and ACF Blocks as PRO features. And the REST API support is in the free plugin: since ACF 5.11 it is an opt-in per field group (Show in REST API under Group Settings). Older guides, including an earlier version of this one, said you need a separate plugin for that. You do not.

Situation

Native meta

ACF

A few text, number or date fields

Fits. Register and bind, no dependency.

Works, but adds a plugin for little gain.

Repeating rows, flexible layouts, galleries

Possible, with real custom UI work.

Pro feature built for it.

Editors or clients design the fields

Needs developer time per change.

Fits. Field groups are edited in the admin.

Plugin you give to others

Fits. No dependency to explain.

Adds a hard dependency.

Headless or REST use

Register with show_in_rest and a schema.

Opt in per field group.

One risk to name. Fields stored by ACF are plain post meta, so your data survives removing the plugin, but ACF’s own field keys and formatting do not. Decide before launch which one owns the schema.

How do you query a custom post type?

Pass post_type to WP_Query, or let the main query do it on the archive URL. To change the main archive query, use pre_get_posts and check is_admin(), is_main_query() and is_post_type_archive() first. Otherwise you will change queries you did not mean to.

<?php
add_action(
	'pre_get_posts',
	static function ( $query ) {
		if ( is_admin() || ! $query->is_main_query() || ! $query->is_post_type_archive( 'acme_project' ) ) {
			return;
		}
		$query->set( 'posts_per_page', 12 );
		$query->set( 'orderby', 'date' );
		$query->set( 'order', 'DESC' );
	}
);

// A secondary query, for example on a landing page.
$projects = new WP_Query(
	array(
		'post_type'      => 'acme_project',
		'posts_per_page' => 6,
		'no_found_rows'  => true,
		'tax_query'      => array(
			array(
				'taxonomy' => 'acme_service',
				'field'    => 'slug',
				'terms'    => 'web-design',
			),
		),
	)
);

Use get_post_type_archive_link( 'acme_project' ) for the archive URL, never a hard-coded path, since the slug can change. Set no_found_rows to true on queries where you do not paginate, which skips the count query. On sites with thousands of rows, avoid sorting or filtering on meta_value without a plan: wp_postmeta indexes the key and post ID, not the value. Page your archives and keep queries bounded.

This also answers the “default post types” part of the search queries: get_post_types( array( 'public' => true ) ) lists what is registered as public on your site, including your own.

Should the code live in a plugin or a theme?

A plugin. Post types are data, and a theme switch should not make that data disappear from the admin and the front end. The rows stay in the database either way, but with the registration in functions.php nothing shows them. The one exception is a site that will keep one theme for its whole life, and even there a small must-use plugin costs nothing. A plugin also gives you an activation hook for the rewrite flush and the capability grants shown above.

Common mistakes people report

These come up again and again in docs notes, support threads and tutorials. Each is paraphrased, linked and was checked on 15 Nov 2026.

  • The type 404s after you register it. The rules need rebuilding, and the fix is one flush, not one on every request. The flush_rewrite_rules reference calls it expensive, and user notes there warn that flushing before the type is registered produces rules without it.
  • The editor falls back to the classic one. The type has no show_in_rest. The register_post_type reference says it must be true for the block editor, and a tutorial updated in Feb 2026 describes the same symptom.
  • Registered meta is missing from the REST response. The REST handbook notes that the post type must support custom-fields for meta to appear, on top of show_in_rest on the key. See modifying responses.
  • revisions_enabled seems to do nothing. The usual causes are a post type without revisions support, a registration that runs before the type exists, or a WordPress version older than 6.4. The 6.4 dev note describes the notice core logs, and WP_DEBUG_LOG will show it.
  • Custom capabilities lock out the administrator. A Meta Box support thread ran from 2018 to 2022 on this: generated capabilities needed map_meta_cap, every role (administrators too) needed the grants, and the names had to match the singular and plural base exactly.
  • An unprefixed or overlong key. A user note on the register_post_type page warns about the 20 character limit. Prefix your keys so two plugins cannot collide.

Which registration pattern fits your project?

Your situation

Do this

Public content with its own URLs

public true, has_archive, rewrite slug, flush on activation.

Admin-only records

public false, show_ui true, custom capabilities, no rewrite.

Headless or app front end

show_in_rest true, rest_base, registered meta with schemas.

Content with a fixed structure

template and template_lock, plus block bindings in the theme.

Content people edit often

supports includes revisions and meta uses revisions_enabled.

Frequently asked questions

Do I need register_post_meta for custom fields to work?

No. update_post_meta() saves any key. Registering adds REST access, type handling, defaults, sanitising and revision support.

Which WordPress version added revisions_enabled?

WordPress 6.4. The @since 6.4.0 note sits on register_meta() in core, and the feature was announced on 24 Oct 2023.

Why does register_meta return false for my revisions_enabled key?

Either the object type is not post, or the post type does not support revisions at that moment. Register the type first and list revisions in supports.

How many characters can a post type key have?

Twenty. Taxonomy keys can have 32.

Should I call flush_rewrite_rules in my theme or plugin?

In a plugin activation hook, once, after registering the type. Not on init.

Can I change the slug of a custom post type later?

The key lives in the database on every row, so changing it orphans existing posts until you update them. Changing only the rewrite slug is safe, and needs one rule flush.

Does show_in_rest make my content public?

For a public type, yes, published items are readable through the API without authentication. Treat it like the front end.

Where to go next

Add REST routes of your own with custom REST API endpoints, secure writes with the authentication guide, and keep the plugin upgrade-safe with the activation and upgrade path guide. The official sources for everything above are the register_post_type and register_meta references.

Varun Dubey

Written by

Varun Dubey

Varun Dubey runs Wbcom Designs, the WordPress studio he founded in India in 2009. He has spent sixteen years building on WordPress and BuddyPress, shipping client work and products such as Reign, BuddyX, Jetonomy and MediaVerse, and has been putting Claude and OpenAI workflows into production since 2023. He writes up what the studio learns along the way.

More about Varun

No comments yet