Custom Post Types
Custom Post Types (CPTs) are user-defined content types in WordPress that extend the default post and page types. They allow you to create structured content like portfolios, testimonials, products, events, or any content type specific to your site's needs, with its own admin interface and template files.
§ 1 Definition
Custom Post Types (CPTs) are a WordPress feature that lets you define new content types beyond the built-in Posts and Pages. While WordPress natively handles blog posts ('post') and static pages ('page'), CPTs allow you to create any content structure your project needs. For example, a real estate site might register a 'Property' CPT with custom fields for price, bedrooms, square footage, and location. A restaurant site might register a 'Menu Item' CPT with fields for ingredients, price, dietary tags, and images. Each CPT gets its own admin menu section, editor interface, and template system. CPTs are registered using the `register_post_type()` function in your theme's `functions.php` file or a custom plugin. They can be hierarchical (like Pages, with parent/child relationships) or non-hierarchical (like Posts, with flat organization). Along with CPTs, developers typically register custom Taxonomies to classify and filter CPT content.
§ 2 Registering Custom Post Types
A Custom Post Type is registered using the `register_post_type()` function with a set of arguments that control its behavior:
§ 3 CPT Use Cases
Custom Post Types transform WordPress from a blogging platform into a general-purpose CMS. Common use cases include: - Portfolio: Showcase projects with client name, date, project URL, and case study content. - Testimonials: Customer quotes with attribution, company, and rating. - Products: Ecommerce items (though WooCommerce handles this more fully). - Events: Calendar entries with date, time, location, and registration. - Team Members: Staff profiles with position, bio, photo, and social links. - Case Studies: In-depth project write-ups with results, methodology, and client quotes. - Courses: Educational content with modules, lessons, and progress tracking. - Properties: Real estate listings with price, location, features, and images. The key advantage is that each CPT has its own admin section, making content management organized and intuitive. Content editors don't mix employee profiles with blog posts in the same 'Posts' list.
§ 4 CPT Templates and Display
WordPress's Template Hierarchy automatically supports custom post types. You create template files following naming conventions: - `single-{post_type}.php` (e.g., `single-property.php`) for individual CPT items. - `archive-{post_type}.php` (e.g., `archive-property.php`) for the CPT archive list. - `taxonomy-{taxonomy}.php` if you've registered custom taxonomies. If these template files don't exist, WordPress falls back to `single.php`, `archive.php`, and ultimately `index.php`. This makes CPTs graceful to implement even without custom templates. For block themes (FSE), CPT templates are defined as block patterns in the Site Editor. The same template hierarchy logic applies, but templates are HTML files edited through the visual interface rather than PHP files. CPT permalinks are configurable too. A 'property' CPT can have URLs like `/properties/123-main-street/` or `/listings/houses/123-main-street/` depending on your rewrite rules.
§ 5 In code
// Register a 'property' Custom Post Type
function ag_register_property_cpt() {
$args = array(
'labels' => array(
'name' => 'Properties',
'singular_name' => 'Property',
'add_new_item' => 'Add New Property',
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'properties'),
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'menu_icon' => 'dashicons-building',
'show_in_rest' => true, // Enable Gutenberg editor
);
register_post_type('property', $args);
}
add_action('init', 'ag_register_property_cpt');§ 6 Common questions
- Q. Should I put CPT code in functions.php or a plugin?
- A. A plugin. If you put CPT registration in your theme's functions.php, deactivating the theme removes the CPT and its data from the admin. A custom plugin keeps your content accessible even when switching themes.
- Q. Can I create CPTs without code?
- A. Yes. The Custom Post Type UI (CPT UI) plugin provides a visual interface for registering CPTs and taxonomies. It's a good option for non-developers or rapid prototyping.
- Q. Do CPTs affect database performance?
- A. Not directly. CPT data is stored in the wp_posts table with a post_type column for differentiation. Very large numbers of CPT entries (100,000+) may require database optimization like any large WordPress dataset.
- Custom Post Types extend WordPress beyond posts and pages, creating dedicated content structures for any use case.
- CPTs are registered with register_post_type() and get their own admin area, templates, and permalink structure.
- Always register CPTs in a plugin, not a theme, to preserve content when switching themes.
- CPTs combined with custom taxonomies create a powerful, structured CMS out of WordPress.
We design and build custom post type architectures for WordPress projects that need structured content. Portfolio, team, events, properties, products. Clean admin interfaces, optimized templates, and fast queries. Get in touch about your WordPress project.
Get in touchCustom Post Types (CPTs) are user-defined content types in WordPress that extend the default post and page types. They allow you to create structured content like portfolios, testimonials, products, events, or any content type specific to your site's needs, with its own admin interface and template files.
Category: Cms (also: Software Engineering)
Author: Atomic Glue Editorial Team
## Definition
Custom Post Types (CPTs) are a WordPress feature that lets you define new content types beyond the built-in Posts and Pages. While WordPress natively handles blog posts ('post') and static pages ('page'), CPTs allow you to create any content structure your project needs. For example, a real estate site might register a 'Property' CPT with custom fields for price, bedrooms, square footage, and location. A restaurant site might register a 'Menu Item' CPT with fields for ingredients, price, dietary tags, and images. Each CPT gets its own admin menu section, editor interface, and template system. CPTs are registered using the `register_post_type()` function in your theme's `functions.php` file or a custom plugin. They can be hierarchical (like Pages, with parent/child relationships) or non-hierarchical (like Posts, with flat organization). Along with CPTs, developers typically register custom [Taxonomies](/glossary/taxonomies) to classify and filter CPT content.
## Registering Custom Post Types
A Custom Post Type is registered using the `register_post_type()` function with a set of arguments that control its behavior:
## CPT Use Cases
Custom Post Types transform WordPress from a blogging platform into a general-purpose [CMS](/glossary/cms). Common use cases include: - **Portfolio:** Showcase projects with client name, date, project URL, and case study content. - **Testimonials:** Customer quotes with attribution, company, and rating. - **Products:** Ecommerce items (though WooCommerce handles this more fully). - **Events:** Calendar entries with date, time, location, and registration. - **Team Members:** Staff profiles with position, bio, photo, and social links. - **Case Studies:** In-depth project write-ups with results, methodology, and client quotes. - **Courses:** Educational content with modules, lessons, and progress tracking. - **Properties:** Real estate listings with price, location, features, and images. The key advantage is that each CPT has its own admin section, making content management organized and intuitive. Content editors don't mix employee profiles with blog posts in the same 'Posts' list.
## CPT Templates and Display
WordPress's [Template Hierarchy](/glossary/template-hierarchy) automatically supports custom post types. You create template files following naming conventions: - `single-{post_type}.php` (e.g., `single-property.php`) for individual CPT items. - `archive-{post_type}.php` (e.g., `archive-property.php`) for the CPT archive list. - `taxonomy-{taxonomy}.php` if you've registered custom taxonomies. If these template files don't exist, WordPress falls back to `single.php`, `archive.php`, and ultimately `index.php`. This makes CPTs graceful to implement even without custom templates. For block themes (FSE), CPT templates are defined as block patterns in the Site Editor. The same template hierarchy logic applies, but templates are HTML files edited through the visual interface rather than PHP files. CPT permalinks are configurable too. A 'property' CPT can have URLs like `/properties/123-main-street/` or `/listings/houses/123-main-street/` depending on your rewrite rules.
## In code
// Register a 'property' Custom Post Type
function ag_register_property_cpt() {
$args = array(
'labels' => array(
'name' => 'Properties',
'singular_name' => 'Property',
'add_new_item' => 'Add New Property',
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'properties'),
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'menu_icon' => 'dashicons-building',
'show_in_rest' => true, // Enable Gutenberg editor
);
register_post_type('property', $args);
}
add_action('init', 'ag_register_property_cpt');## Common questions
Q: Should I put CPT code in functions.php or a plugin?
A: A plugin. If you put CPT registration in your theme's functions.php, deactivating the theme removes the CPT and its data from the admin. A custom plugin keeps your content accessible even when switching themes.
Q: Can I create CPTs without code?
A: Yes. The Custom Post Type UI (CPT UI) plugin provides a visual interface for registering CPTs and taxonomies. It's a good option for non-developers or rapid prototyping.
Q: Do CPTs affect database performance?
A: Not directly. CPT data is stored in the wp_posts table with a post_type column for differentiation. Very large numbers of CPT entries (100,000+) may require database optimization like any large WordPress dataset.
## Key takeaways
- Custom Post Types extend WordPress beyond posts and pages, creating dedicated content structures for any use case.
- CPTs are registered with register_post_type() and get their own admin area, templates, and permalink structure.
- Always register CPTs in a plugin, not a theme, to preserve content when switching themes.
- CPTs combined with custom taxonomies create a powerful, structured CMS out of WordPress.
## Related entries
- [WordPress](atomicglue.co/glossary/wordpress)
- [Taxonomies](atomicglue.co/glossary/taxonomies)
- [Template Hierarchy](atomicglue.co/glossary/template-hierarchy)
- [CMS](atomicglue.co/glossary/cms)
- [Plugins](atomicglue.co/glossary/plugins)
Last updated July 2025. Permalink: atomicglue.co/glossary/custom-post-types