📦 Beyond Posts and Pages
WordPress has Posts and Pages. You need Portfolios, Products, Team Members? Custom Post Types unlock unlimited content structures.
What Are Custom Post Types?
Think of them as custom content containers with their own admin interface, taxonomies, and templates.
💡 Use Cases
- Portfolio: Projects with client, year, category
- Products: E-commerce items (or use WooCommerce)
- Team Members: Staff bios with role, department
- Testimonials: Client reviews with rating, company
- Events: Calendar items with date, location, tickets
- Recipes: Cooking instructions with ingredients, prep time
Create Custom Post Type (Code Method)
// Add to functions.php or custom plugin
function create_portfolio_post_type() {
register_post_type('portfolio',
array(
'labels' => array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio Item',
'add_new' => 'Add New Project',
'add_new_item' => 'Add New Portfolio Item',
'edit_item' => 'Edit Portfolio Item',
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'portfolio'),
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'menu_icon' => 'dashicons-portfolio',
'show_in_rest' => true, // Gutenberg support
)
);
}
add_action('init', 'create_portfolio_post_type');
Result: New “Portfolio” menu appears in WordPress admin. Add portfolio items like posts.
Add Custom Taxonomies
// Add categories and tags for Portfolio
function create_portfolio_taxonomies() {
// Portfolio Categories
register_taxonomy(
'portfolio_category',
'portfolio',
array(
'label' => 'Portfolio Categories',
'hierarchical' => true, // Like categories
'show_in_rest' => true,
)
);
// Portfolio Tags
register_taxonomy(
'portfolio_tag',
'portfolio',
array(
'label' => 'Portfolio Tags',
'hierarchical' => false, // Like tags
'show_in_rest' => true,
)
);
}
add_action('init', 'create_portfolio_taxonomies');
🔌 Plugin Method (No Code)
Custom Post Type UI plugin → Visual interface to create CPTs
- Install “Custom Post Type UI” plugin
- CPT UI → Add/Edit Post Types
- Fill in labels, slug, options
- Click “Add Post Type”
- Done! No coding needed
Display Custom Posts in Theme
// Create template: archive-portfolio.phpOur Portfolio
'portfolio', 'posts_per_page' => 12, 'orderby' => 'date', 'order' => 'DESC' ); $portfolio_query = new WP_Query($args); if ($portfolio_query->have_posts()) : while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?>
🎯 Advanced: Custom Fields
Add custom data to your CPT with Advanced Custom Fields (ACF) plugin:
- Portfolio: Client Name, Project Year, Website URL
- Team Member: Job Title, Email, Phone, LinkedIn
- Event: Event Date, Location, Ticket Price
- Recipe: Prep Time, Cook Time, Servings, Ingredients
💡 Best Practices
- Slug naming: Use singular (portfolio, not portfolios)
- Enable REST API: ‘show_in_rest’ => true for Gutenberg/API access
- Archive pages: ‘has_archive’ => true to get yoursite.com/portfolio
- URL structure: Use ‘rewrite’ to customize URLs
- Icon: Choose from Dashicons for recognizable menu icon
“Client wanted portfolio showcase separate from blog. Created custom post type with categories for Web, Branding, Photography. Now they manage it themselves. Clean, organized, professional.”
