how to create custom post type in wordpres

So you’ve been using WordPress for a while, and you’re starting to feel a bit limited by just having “posts” and “pages,” right? I totally get it. Sometimes you need something more specific – maybe you’re building a portfolio site and need a dedicated section for your work, or you’re creating a restaurant website that needs separate areas for menu items and events. That’s when you realize it’s time to create a custom post type.
Once you learn how to create custom post type in WordPress, you’ll unlock a whole new level of flexibility—and trust me, you’ll wonder how you ever lived without it.
What Exactly Are Custom Post Types?
Think of custom post types as specialized filing cabinets for your content. Instead of shoving everything into the generic “posts” drawer, you can create specific compartments for different types of content.
Let’s say you’re building that restaurant website I mentioned. You could create custom post types for:
- Menu items (with fields for price, ingredients, allergen info)
- Special events (with date, time, and booking details)
- Chef profiles (with photos, bios, and specialties)
- Customer reviews (with ratings and photos)
Each type can have its own unique fields and display options. Pretty cool, right?
Why Bother with Custom Post Types?
Before we dive into the technical stuff, let me convince you why this is worth your time:
Your content stays organized. No more scrolling through dozens of regular blog posts to find that one menu item you need to update. Everything has its place.
Your visitors will thank you. When someone visits your restaurant site, they want to see the menu, not your latest blog post about hiring new staff. Custom post types let you create dedicated sections that make sense.
Search engines love structure. Google and friends can better understand what your content is about when it’s properly organized. This can actually help your SEO.
You’ll look more professional. Instead of having a generic blog-style site, you’ll have something that looks purpose-built for your specific needs.
Method 1: Getting Your Hands Dirty with Code
I know, I know – “code” can be a scary word. But hear me out. This method gives you complete control, and it’s not as intimidating as it sounds.
Your First Custom Post Type
Here’s a simple example that creates a “Products” section for your site:
<?php
function create_custom_post_types() {
register_post_type('products', array(
'labels' => array(
'name' => 'Products',
'singular_name' => 'Product',
'add_new' => 'Add New Product',
'add_new_item' => 'Add New Product',
'edit_item' => 'Edit Product',
'new_item' => 'New Product',
'view_item' => 'View Product',
'search_items' => 'Search Products',
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'products'),
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'menu_icon' => 'dashicons-cart',
'show_in_rest' => true,
));
}
add_action('init', 'create_custom_post_types');

Just paste this into your theme’s functions.php file, and boom – you’ll see a new “Products” menu in your WordPress admin.
Breaking Down What This Code Does
Let me explain what’s happening here (without getting too technical):
- labels: These are just the names that show up in your admin area
- public: Set to
trueso people can actually see this content on your site - has_archive: Creates a page that lists all your products (like yoursite.com/products/)
- rewrite: Controls what the URLs look like
- supports: Decides what editing features you get (title, content editor, featured images, etc.)
- menu_icon: That little icon in your admin menu (you can browse Dashicons for options)
- show_in_rest: Enables the modern block editor and REST API
A More Advanced Example
Once you’re comfortable with the basics, you might want something more sophisticated. Here’s an example for a portfolio site:
<?php
function create_portfolio_post_type() {
register_post_type('portfolio', array(
'labels' => array(
'name' => 'Portfolio Items',
'singular_name' => 'Portfolio Item',
'menu_name' => 'Portfolio',
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'work'),
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'menu_icon' => 'dashicons-portfolio',
'show_in_rest' => true,
'menu_position' => 5,
));
}
add_action('init', 'create_portfolio_post_type');
Method 2: The Plugin Route (For Code-Shy Folks)
Not everyone wants to mess around with code, and that’s perfectly fine! The Custom Post Type UI plugin is your friend here.
Getting Started with the Plugin
- Go to your WordPress admin and navigate to Plugins > Add New
- Search for “Custom Post Type UI”
- Install and activate it
- You’ll see a new “CPT UI” menu item appear
Creating Your Custom Post Type
Once you’ve got the plugin activated:
- Click on CPT UI > Add/Edit Post Types
- Fill in the basic info:
- Post Type Slug: This is the internal name (use lowercase, no spaces – like “products” or “team-members”)
- Plural Label: What you want to call multiple items (“Products”, “Team Members”)
- Singular Label: What you want to call one item (“Product”, “Team Member”)
- Scroll through the other settings and adjust as needed
- Hit Add Post Type
The plugin interface is pretty intuitive, and you can see exactly what you’re doing without touching any code.
Making Your Content Even More Organized with Custom Taxonomies
Here’s where things get really powerful. Custom taxonomies are like categories and tags, but specific to your custom post types.
For example, if you have a portfolio, you might want taxonomies for:
- Project type (web design, branding, photography)
- Client industry (healthcare, tech, retail)
- Year completed
Here’s how to add a custom taxonomy with code:
<?php
function create_portfolio_taxonomies() {
register_taxonomy('project_type', 'portfolio', array(
'labels' => array(
'name' => 'Project Types',
'singular_name' => 'Project Type',
),
'public' => true,
'hierarchical' => true, // Like categories
'rewrite' => array('slug' => 'project-type'),
'show_in_rest' => true,
));
}
add_action('init', 'create_portfolio_taxonomies');
Actually Showing Your Custom Post Types on Your Site
Creating the custom post type is only half the battle. Now you need to display it on your website. Here are a few ways to do that:
Option 1: Create Custom Template Files
This is the most flexible approach. Create these files in your active theme folder:
archive-portfolio.php– Shows a list of all portfolio itemssingle-portfolio.php– Shows individual portfolio items
WordPress will automatically use these templates when someone visits your custom post type pages.
Option 2: Use a Custom Query
You can display custom post types anywhere on your site with a bit of code:
<?php
$portfolio_items = new WP_Query(array(
'post_type' => 'portfolio',
'posts_per_page' => 6,
));
if ($portfolio_items->have_posts()) {
while ($portfolio_items->have_posts()) {
$portfolio_items->the_post();
// Display your content here
the_title();
the_content();
}
}
wp_reset_postdata();
Option 3: Include Them in Your Main Feed
Want your custom post types to show up in your main blog feed or search results? Add this to your functions.php:
<?php
function include_custom_post_types_in_main_query($query) {
if (is_home() && $query->is_main_query()) {
$query->set('post_type', array('post', 'portfolio', 'products'));
}
}
add_action('pre_get_posts', 'include_custom_post_types_in_main_query');
Some Hard-Learned Tips
After working with custom post types for years, here’s what I wish someone had told me earlier:
Pick good names from the start. Don’t use generic slugs like “items” or “stuff.” Be specific – “team-members,” “case-studies,” “products.” You’ll thank yourself later.
Plan your structure first. Before you start creating custom post types, sit down and think about what fields and categories you’ll need. It’s much easier to get it right the first time than to restructure everything later.
Test on mobile. Always check how your custom post types look on phones and tablets. Make sure your custom templates are responsive.
Consider using Advanced Custom Fields. If you need custom fields (like price, project date, client name), the ACF plugin is incredibly helpful and user-friendly.
Think about performance. If you’re planning to have hundreds or thousands of items, make sure you’re using pagination and consider caching solutions.
When Things Go Wrong (Troubleshooting)
Custom Post Type Not Showing Up?
This happens more often than you’d think. Try these fixes:
- Flush your permalinks: Go to Settings > Permalinks and click “Save Changes”
- Check your code: Make sure you have
'public' => truein your register_post_type function - Look for syntax errors: One missing comma can break everything
Getting 404 Errors on Custom Post Pages?
This is usually a permalink issue. Go to Settings > Permalinks and save the settings again. WordPress needs to regenerate its URL structure.
Custom Posts Not Showing in Search?
By default, WordPress search only looks through regular posts and pages. If you want to include custom post types, add this code:
<?php
function include_custom_post_types_in_search($query) {
if ($query->is_search() && $query->is_main_query() && !is_admin()) {
$query->set('post_type', array('post', 'page', 'portfolio', 'products'));
}
}
add_action('pre_get_posts', 'include_custom_post_types_in_search');
Wrapping This Up
Custom post types might seem like overkill at first, but they’re honestly one of the best features of WordPress. They let you move beyond the basic blog structure and create websites that are perfectly tailored to your needs.
Start simple – create one custom post type for something you actually need. Get comfortable with how it works, then gradually add more features as you need them.
The goal isn’t to make your site more complicated – it’s to make it more useful and organized. And trust me, once you start thinking in terms of custom post types, you’ll see opportunities to use them everywhere.
Your future self (and your clients, if you build sites for others) will definitely appreciate the extra structure and professionalism that custom post types bring to your WordPress projects.