Custom Post Type
A Custom Post Type in WordPress is a content type beyond the default ones like Posts and Pages. It allows developers and site owners to create structured content tailored to specific use cases – such as portfolios, testimonials, events, products, or services.
Built-in Post Types in WordPress
WordPress comes with several built-in post types:
post
– blog postspage
– static pagesattachment
– media uploadsrevision
– content revisionsnav_menu_item
– menu items
What Is a Custom Post Type?
Custom Post Types behave like posts or pages, but they can have their own admin menu, templates, metadata, taxonomies, and URLs.
Example: Registering a Custom Post Type
function create_movie_post_type() {
register_post_type('movie', [
'labels' => [
'name' => 'Movies',
'singular_name' => 'Movie'
],
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'movies'],
'supports' => ['title', 'editor', 'thumbnail'],
]);
}
add_action('init', 'create_movie_post_type');
Use Cases
- Portfolios – for designers or agencies
- Testimonials – client reviews
- Events – with custom fields like date, location
- Products – when not using WooCommerce
- Team Members – structured staff bios
Displaying CPT Content
To display custom post type content on the frontend, you can:
- Use
WP_Query
withpost_type => 'your_type'
- Create custom templates:
single-glossary.php
,archive-glossary.php
- Use page builders or CPT-compatible blocks
Summary
Feature | Description |
---|---|
What it is | Custom content type beyond Posts and Pages |
Use cases | Portfolios, Events, Products, Testimonials, etc. |
How to register | register_post_type() in functions.php or plugin |
Template support | Custom single and archive templates |
Enhancements | Works with taxonomies, custom fields, Gutenberg, REST |