📚 Understanding Custom Post Types
Extend WordPress beyond posts and pages
Learn how Custom Post Types enable diverse content structures
Learning Objectives
- Understand what Custom Post Types are
- Learn when to use Custom Post Types
- Explore built-in vs custom post types
- Understand CPT capabilities and features
- Learn about hierarchical vs non-hierarchical CPTs
- Explore real-world use cases
- Understand CPT architecture in WordPress
- Learn best practices for CPT planning
What Are Custom Post Types?
Custom Post Types (CPTs) are a way to create different content types in WordPress beyond the default posts and pages. They allow you to organize and display different types of content with their own attributes, templates, and admin interfaces.
Why Use Custom Post Types?
- Content Organization: Separate different types of content logically
- Custom Fields: Add specific metadata relevant to each content type
- Custom Templates: Create unique designs for each content type
- Admin Organization: Separate menu items and management interfaces
- Custom Capabilities: Control user permissions per content type
- Better URLs: Create semantic URL structures
- Scalability: Manage large amounts of structured content
WordPress Built-in Post Types
WordPress comes with several built-in post types that you're already familiar with:
| Post Type | Purpose | Features | Hierarchical |
|---|---|---|---|
| post | Blog posts and articles | Categories, tags, comments, revisions | No |
| page | Static pages | Page templates, parent/child, page attributes | Yes |
| attachment | Media files | Media library, image sizes, metadata | No |
| revision | Post/page versions | Version history, restore functionality | No |
| nav_menu_item | Navigation menu items | Menu management | No |
| custom_css | Custom CSS in Customizer | Theme customization | No |
| customize_changeset | Customizer changesets | Customizer drafts and scheduling | No |
Custom Post Type Architecture
Each Custom Post Type can have:
- Custom Fields: Additional data fields specific to the content type
- Custom Taxonomies: Ways to categorize and organize the content
- Custom Templates: Unique display templates for archives and singles
- Custom Capabilities: Specific user permissions
- REST API Support: Exposure through WordPress REST API
- Admin UI: Custom columns, filters, and meta boxes
Common Custom Post Type Examples
Products
E-commerce products with prices, SKUs, inventory
Portfolio
Showcase work with images, descriptions, client info
Events
Events with dates, locations, ticket information
Team Members
Staff profiles with roles, bios, contact info
Testimonials
Customer reviews with ratings and attribution
Courses
Educational content with lessons and curriculum
Properties
Real estate listings with details and galleries
Books
Library or bookstore with authors and genres
Movies
Film database with cast, crew, and reviews
Hierarchical vs Non-Hierarchical CPTs
Hierarchical Post Types (like Pages)
- Can have parent/child relationships
- Support page attributes meta box
- URL structure can reflect hierarchy
- Good for: Documentation, Courses, Product Categories
Non-Hierarchical Post Types (like Posts)
- Flat structure, no parent/child
- Typically organized with taxonomies
- Simpler URL structure
- Good for: Blog posts, Events, Testimonials, Portfolio items
Example URL Structures
// Hierarchical CPT (Courses)
https://site.com/courses/ // Archive
https://site.com/courses/web-development/ // Parent course
https://site.com/courses/web-development/html-basics/ // Child lesson
// Non-Hierarchical CPT (Events)
https://site.com/events/ // Archive
https://site.com/events/summer-conference/ // Single event
https://site.com/events/category/workshops/ // Taxonomy archive
Custom Post Type Capabilities
| Capability | Description | Example |
|---|---|---|
edit_post |
Edit a specific post | edit_product |
read_post |
Read a specific post | read_product |
delete_post |
Delete a specific post | delete_product |
edit_posts |
Edit own posts | edit_products |
edit_others_posts |
Edit posts by other users | edit_others_products |
publish_posts |
Publish posts | publish_products |
read_private_posts |
Read private posts | read_private_products |
delete_posts |
Delete own posts | delete_products |
When to Use Custom Post Types
✅ Use a CPT When:
- Content has unique attributes not suited for posts/pages
- You need separate admin management
- Content requires custom templates
- You want different URL structures
- Content needs specific user capabilities
- You're building structured data (products, events, etc.)
- Content should be queryable separately
❌ Don't Use a CPT When:
- Regular posts or pages work fine
- Content is better as a taxonomy
- You only need a few custom fields
- Content doesn't need separate management
- It's just for styling differences
Custom Post Type Features
Supported Features
Custom Post Types can support various WordPress features:
- title: Post title
- editor: Content editor
- author: Post author
- thumbnail: Featured image
- excerpt: Post excerpt
- trackbacks: Trackback and pingback support
- custom-fields: Custom fields meta box
- comments: Comments capability
- revisions: Post revisions
- page-attributes: Menu order, parent (hierarchical)
- post-formats: Post format support
Example: Defining Supported Features
// When registering a CPT, specify supported features
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments',
'revisions',
'custom-fields',
'page-attributes', // For hierarchical CPTs
)
Planning Your Custom Post Types
Questions to Ask Before Creating a CPT
- What content am I storing?
- What are the key attributes?
- How is it different from posts/pages?
- How will it be organized?
- Does it need categories or tags?
- Should it be hierarchical?
- Who will manage it?
- What user roles need access?
- What capabilities are required?
- How will it be displayed?
- Does it need an archive page?
- What should the URL structure be?
- What features does it need?
- Comments? Revisions? Featured images?
- REST API support?
Best Practices
CPT Planning Best Practices
- Use descriptive names: Make CPT names clear and intuitive
- Follow naming conventions: Use lowercase, underscores for spaces
- Plan URL structure: Consider SEO and user experience
- Think about scalability: Design for future growth
- Consider performance: Don't create unnecessary CPTs
- Document your CPTs: Keep track of purpose and structure
- Test thoroughly: Ensure CPTs work with theme and plugins
- Plan for migration: Consider data portability