Knowledge base — Definition
Custom Post Type
What a WordPress custom post type is, how register_post_type() works, when to use one instead of pages, and the setup mistakes to avoid.
What Is a Custom Post Type?
A custom post type is a content type you register in WordPress alongside the built-in posts and pages, such as Projects, Team Members, Events, Locations or Job Postings, each with its own admin menu, editing screen, URL structure and templates.
Internally, everything in WordPress is stored in the same wp_posts database table, with a post_type column telling them apart. Posts, pages, attachments, revisions and navigation menu items are all post types already. Registering your own simply adds another one, which means it automatically works with WordPress features like revisions, user permissions, search, the REST API and the block editor. Combined with custom fields and custom taxonomies, custom post types are what turn WordPress from a blogging tool into a general-purpose content management system.
Why Custom Post Types Matter
Choosing the right content model early saves a great deal of rework later.
- Cleaner editing: Editors add a new event from an Events menu with fields for date and venue, instead of formatting a generic page by hand.
- Consistent output: Every item of a type uses the same template, so listings and detail pages look uniform.
- Better URLs and archives: Each type can have its own slug, such as
/projects/, and an automatic archive page. - Structured data: Separate fields make it easy to filter, sort, add schema markup or expose content to an app through the REST API.
- Safer permissions: You can give a role access to manage one content type without letting it touch the rest of the site.
How Custom Post Types Work
- Registration: Code calls
register_post_type()on theinithook with a key of 20 characters or fewer, lowercase, with no spaces, plus labels and arguments. - Key arguments:
publiccontrols visibility,has_archivecreates a listing page,rewritesets the URL slug,supportsenables features like title, editor, thumbnail and excerpt, andmenu_iconsets the admin icon. - Block editor and REST API: Setting
show_in_restto true is required for the type to use the block editor and to be available through the REST API. - Taxonomies and fields:
register_taxonomy()adds categories specific to the type, such as Event Type, while custom fields store structured values like dates or prices, often managed with a fields plugin orregister_post_meta(). - Templates: Classic themes use files such as
single-event.phpandarchive-event.php; block themes use matching HTML templates editable in the Site Editor.
Common Custom Post Type Mistakes
- Registering in the theme: If the code lives in the theme, switching themes makes all that content disappear from the admin. It still exists in the database, but nobody can reach it.
- Using reserved names: Keys like
post,page,attachment,revision,action,orderorthemeconflict with core or common plugins. - Forgetting to flush permalinks: New types return 404 errors until rewrite rules are refreshed, which you can do by saving Settings, Permalinks.
- A post type for everything: Creating a type where a category or tag would do. If items share the same fields and only need grouping, use a taxonomy.
- Changing the key later: Renaming a post type key orphans existing content and breaks URLs unless you migrate the data and add redirects.
Best Practices for Custom Post Types
- Model content before building: List each content type, its fields, how it relates to others and where it appears on the site.
- Register types in a plugin: Use a site-specific plugin so content structure is independent of design.
- Prefix your keys: A short prefix avoids collisions with plugins that might register a type with the same name.
- Flush rewrite rules on activation only: Call
flush_rewrite_rules()on plugin activation, never on every page load. - Lock editing where it helps: Use block templates to give each type a predefined layout so editors fill in content rather than design pages.
- Plan for search and SEO: Decide which types should be indexed, include them in your XML sitemap and give archives useful introductions.
Custom Post Types at PerfectPixels
Content modelling is one of the first things we do on a WordPress development project. We register post types, taxonomies and fields in a dedicated plugin, design editing screens around how your team actually works, and build templates for each type. Our custom WordPress platform case study shows this approach in practice.
Frequently Asked Questions
When should I use a custom post type instead of a page?
Use a custom post type when you have many items of the same kind that share fields and should be listed, filtered or displayed the same way, such as team members or properties. Use pages for one-off content like About or Contact.
Do I need a plugin to create a custom post type?
No. A few lines of PHP with register_post_type() are enough. Plugins with a settings interface exist, but defining types in code keeps them in version control and avoids another dependency.
Will my content be lost if I deactivate the code that registers a post type?
No. The content stays in the database but is hidden from the admin and front end until the type is registered again. That is why registration belongs in a plugin rather than a theme.
Related Resources
Further reading: Custom post types — WordPress Developer Resources.

