Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Create Custom Post Types for Portfolios, Products, Reviews

- 22.03.26 - ErcanOPAK

📦 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

  1. Install “Custom Post Type UI” plugin
  2. CPT UI → Add/Edit Post Types
  3. Fill in labels, slug, options
  4. Click “Add Post Type”
  5. Done! No coding needed

Display Custom Posts in Theme

// Create template: archive-portfolio.php



Our 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(); ?>

View Project

🎯 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.”

— WordPress Developer

Related posts:

WordPress: Dequeueing Unused CSS/JS from Plugins to Improve LCP

WordPress Slow First Load — Autoloaded Options Table

The White Screen of Death Fix (WP_DEBUG)

Post Views: 5

Post navigation

Photoshop: Use Adjustment Layers for Non-Destructive Color Correction
WordPress: Enable Object Caching with Redis for 10x Performance

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com