Posts and Pages are WordPress's built-in content types. But what about a portfolio of projects? A team member directory? A list of testimonials? A recipe collection? These are all content types that don't fit neatly into Posts or Pages — and WordPress gives you the tools to create exactly the right content type for any data.
Custom Post Types (CPTs) let you register entirely new content types with their own admin menu items, capabilities, labels, URL structures, REST API endpoints, and support for specific editor features.
This guide covers everything you need to know about implementing custom post types professionally — from basic registration to advanced customisation.
In WordPress, everything stored in the wp_posts table is a "post" in the database sense — including Pages, Attachments (media), Navigation Menus, and Revisions. These are all technically post types, just different ones.
A Custom Post Type is simply a new entry in this family — registered by your theme or plugin to represent a specific type of content with its own:
/portfolio/project-name/)/wp-json/wp/v2/portfolio)Always register custom post types from a plugin, not a theme. A CPT registered in a theme disappears (along with all its content) when the theme is switched.
add_action( 'init', 'register_portfolio_post_type' );
function register_portfolio_post_type() {
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio Item',
'menu_name' => 'Portfolio',
'add_new' => 'Add New',
'add_new_item' => 'Add New Portfolio Item',
'new_item' => 'New Portfolio Item',
'edit_item' => 'Edit Portfolio Item',
'view_item' => 'View Portfolio Item',
'all_items' => 'All Portfolio Items',
'search_items' => 'Search Portfolio',
'not_found' => 'No portfolio items found.',
'not_found_in_trash' => 'No portfolio items found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true, // Publicly accessible
'publicly_queryable' => true, // Can be queried via URL
'show_ui' => true, // Show in admin
'show_in_menu' => true, // Show in admin sidebar
'query_var' => true, // Enable ?portfolio=slug queries
'rewrite' => array(
'slug' => 'portfolio', // URL prefix: /portfolio/item-slug/
),
'capability_type' => 'post', // Use standard post capabilities
'has_archive' => true, // Enable /portfolio/ archive page
'hierarchical' => false, // Like posts (not pages)
'menu_position' => 20, // Position in admin sidebar
'menu_icon' => 'dashicons-portfolio', // Admin menu icon
'supports' => array(
'title', // Title field
'editor', // Content editor
'thumbnail', // Featured image
'excerpt', // Excerpt field
'custom-fields', // Custom fields panel
'revisions', // Revision history
'page-attributes', // Order and parent (useful for hierarchical CPTs)
),
'show_in_rest' => true, // Enable REST API and block editor
'rest_base' => 'portfolio', // REST API endpoint: /wp-json/wp/v2/portfolio
);
register_post_type( 'portfolio', $args );
}
Flush rewrite rules after registration:
After registering a new CPT, the URL rewrite rules need to be flushed. Do this automatically on plugin activation:
register_activation_hook( __FILE__, function() {
register_portfolio_post_type(); // Register before flushing
flush_rewrite_rules();
});
register_deactivation_hook( __FILE__, function() {
flush_rewrite_rules();
});
Taxonomies are the classification system for post types — similar to Categories and Tags but specific to your custom post type.
add_action( 'init', 'register_portfolio_taxonomy' );
function register_portfolio_taxonomy() {
$labels = array(
'name' => 'Portfolio Categories',
'singular_name' => 'Portfolio Category',
'search_items' => 'Search Categories',
'all_items' => 'All Categories',
'parent_item' => 'Parent Category',
'parent_item_colon' => 'Parent Category:',
'edit_item' => 'Edit Category',
'update_item' => 'Update Category',
'add_new_item' => 'Add New Category',
'new_item_name' => 'New Category Name',
'menu_name' => 'Categories',
);
register_taxonomy(
'portfolio_category', // Taxonomy name
'portfolio', // Post type(s) to attach to
array(
'labels' => $labels,
'hierarchical' => true, // true = like categories, false = like tags
'public' => true,
'show_ui' => true,
'show_admin_column' => true, // Show in post list admin column
'query_var' => true,
'rewrite' => array( 'slug' => 'portfolio-category' ),
'show_in_rest' => true, // Enable REST API and block editor
)
);
}
hierarchical to true for category-style behaviour (parent/child) or false for tag-style behaviour (flat).Custom Post Types often need data beyond title and content — portfolio items need client name, project URL, technologies used; team members need job title, department, LinkedIn URL.
Advanced Custom Fields (ACF) is the standard solution. The free version handles most use cases; ACF Pro adds repeater fields, flexible content, and relationship fields.
Register field groups in PHP rather than through the UI — keeps configuration in version control:
add_action( 'acf/init', 'register_portfolio_fields' );
function register_portfolio_fields() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return; // ACF not active
}
acf_add_local_field_group( array(
'key' => 'group_portfolio_details',
'title' => 'Portfolio Details',
'fields' => array(
array(
'key' => 'field_client_name',
'label' => 'Client Name',
'name' => 'client_name',
'type' => 'text',
),
array(
'key' => 'field_project_url',
'label' => 'Project URL',
'name' => 'project_url',
'type' => 'url',
),
array(
'key' => 'field_technologies',
'label' => 'Technologies Used',
'name' => 'technologies',
'type' => 'textarea',
'rows' => 3,
),
array(
'key' => 'field_featured',
'label' => 'Featured Project',
'name' => 'is_featured',
'type' => 'true_false',
'default_value' => 0,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'portfolio',
),
),
),
) );
}
$client_name = get_field( 'client_name' );
$project_url = get_field( 'project_url' );
$technologies = get_field( 'technologies' );
$is_featured = get_field( 'is_featured' );
The default admin list for your CPT shows only title and date. Add meaningful columns for better usability:
// Add columns to Portfolio admin list
add_filter( 'manage_portfolio_posts_columns', 'portfolio_admin_columns' );
function portfolio_admin_columns( $columns ) {
$new_columns = array();
// Insert after the checkbox
foreach ( $columns as $key => $value ) {
$new_columns[ $key ] = $value;
if ( $key === 'title' ) {
$new_columns['client_name'] = 'Client';
$new_columns['is_featured'] = 'Featured';
}
}
return $new_columns;
}
// Populate the columns
add_action( 'manage_portfolio_posts_custom_column', 'portfolio_admin_column_content', 10, 2 );
function portfolio_admin_column_content( $column, $post_id ) {
switch ( $column ) {
case 'client_name':
$client = get_post_meta( $post_id, 'client_name', true );
echo esc_html( $client ?: '—' );
break;
case 'is_featured':
$featured = get_post_meta( $post_id, 'is_featured', true );
echo $featured ? '⭐ Featured' : '—';
break;
}
}
// Make columns sortable
add_filter( 'manage_edit-portfolio_sortable_columns', 'portfolio_sortable_columns' );
function portfolio_sortable_columns( $columns ) {
$columns['client_name'] = 'client_name';
return $columns;
}
Setting 'show_in_rest' => true in the CPT registration automatically creates a REST API endpoint. You can further customise the REST API integration — for example, adding ACF fields to the response:
// Add ACF fields to the REST API response
add_action( 'rest_api_init', function() {
register_rest_field(
'portfolio',
'acf_fields',
array(
'get_callback' => function( $post ) {
if ( function_exists( 'get_fields' ) ) {
return get_fields( $post['id'] );
}
return null;
},
)
);
});
Now GET /wp-json/wp/v2/portfolio returns portfolio items with ACF field data included.
$portfolio_query = new WP_Query( array(
'post_type' => 'portfolio',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => 'web-design',
),
),
) );
if ( $portfolio_query->have_posts() ) {
while ( $portfolio_query->have_posts() ) {
$portfolio_query->the_post();
$client = get_post_meta( get_the_ID(), 'client_name', true );
// Output each portfolio item
}
wp_reset_postdata(); // Reset after custom query
}
// Get only featured portfolio items
$featured_portfolio = new WP_Query( array(
'post_type' => 'portfolio',
'posts_per_page' => 6,
'meta_query' => array(
array(
'key' => 'is_featured',
'value' => '1',
'compare' => '=',
),
),
) );
$items = get_posts( array(
'post_type' => 'portfolio',
'numberposts' => 6,
'orderby' => 'title',
'order' => 'ASC',
) );
foreach ( $items as $item ) {
echo '<h3>' . esc_html( $item->post_title ) . '</h3>';
}
For non-developer users, or for a UI-based CPT management approach, Custom Post Type UI (CPT UI) plugin provides a visual interface for registering CPTs and taxonomies without code.
Useful for rapid prototyping or client handover — but production sites typically migrate to code-based registration for maintainability and version control.
| Argument | Type | Purpose | Common Value |
|---|---|---|---|
public | Boolean | Whether publicly accessible | true |
show_in_rest | Boolean | Enable REST API and block editor | true |
has_archive | Boolean | Enable archive page at /slug/ | true |
hierarchical | Boolean | Like pages (true) or posts (false) | false |
rewrite.slug | String | URL prefix for the post type | 'portfolio' |
capability_type | String | Permissions system to use | 'post' |
menu_position | Integer | Position in admin sidebar | 20 |
menu_icon | String | Dashicon class for admin menu | 'dashicons-portfolio' |
supports | Array | Enabled editor features | See below |
show_admin_column | Boolean | Show taxonomy in admin list (taxonomy arg) | true |
supports Array Options| Support | Enables | When to Include |
|---|---|---|
'title' | Title field | Almost always |
'editor' | Content editor (Gutenberg) | Most content types |
'thumbnail' | Featured image | When images are needed |
'excerpt' | Excerpt field | For list/archive displays |
'custom-fields' | Custom fields meta box | If not using ACF exclusively |
'revisions' | Revision history | For important content |
'page-attributes' | Page parent/order | Hierarchical CPTs only |
'author' | Author selector | Multi-author sites |
'trackbacks' | Pingbacks/trackbacks | Rarely needed |
| Aspect | Non-Hierarchical (false) |
Hierarchical (true) |
|---|---|---|
| Like | Posts | Pages |
| Parent/Child | No | Yes |
| Taxonomy style | Tags (flat) | Categories (nested) |
| URL structure | /slug/post-slug/ | /slug/parent-slug/post-slug/ |
| Use for | Portfolio, Recipes, Testimonials | Documentation, Services, Knowledge Base |
rewrite argument changes (the URL slug) or when the has_archive setting changes. For other changes (labels, capabilities, supports), no flush is needed. On production, do this by visiting Settings → Permalinks.
show_in_rest is set to true in your CPT registration arguments. The block editor uses the REST API — CPTs not in the REST API aren't available in the block editor's query blocks.
category and post_tag taxonomies when registering your CPT by adding them to the taxonomies argument: 'taxonomies' => array( 'category', 'post_tag' ). However, creating custom taxonomies specific to your CPT is generally better practice for clean data separation.
wp_posts database table — they just revert to showing as regular "posts" in the admin. This is why registering CPTs in plugins is critical: a theme switch doesn't delete your plugin, so your CPTs stay registered. Always back up before modifying CPT registration.
Custom Post Types are one of WordPress's most powerful content architecture features. They let you model any kind of content — with appropriate labels, URL structures, taxonomies, custom fields, and admin interfaces — in a way that makes content management intuitive for editors while maintaining clean data architecture for developers.
Register CPTs in plugins, use ACF for custom fields, customise admin columns for usability, and expose CPTs in the REST API for headless or API-based workflows.
Need custom post types built for your WordPress project? Our development team creates clean, well-architected CPTs with proper taxonomies, custom fields, and admin customisation.
Contact us today and we'll sort it out.