By default, WordPress ships with standard post types: Posts (blog articles), Pages (static pages), and Attachments (media). However, real-world commercial websites rarely fit into just posts and pages. A university portal needs Courses and Faculty; an agency needs a Portfolio; a real estate site needs Properties; a culinary blog needs Recipes. With Custom Post Types (CPT), WordPress transforms from a basic blogging engine into an enterprise-grade Relational Content Platform.
Figure 32.1: Custom Post Types, Taxonomies & Custom Fields Content Modeling Architecture
In professional engineering, Custom Post Types are registered inside a custom site functionality plugin (or child theme functions.php) hooked into the init action hook. Here is the complete production boilerplate:
// Register "Courses" Custom Post Type for an Educational Portal
add_action('init', 'veewom_register_course_cpt');
function veewom_register_course_cpt() {
$labels = array(
'name' => _x('Courses', 'Post Type General Name', 'veewom'),
'singular_name' => _x('Course', 'Post Type Singular Name', 'veewom'),
'menu_name' => __('Courses', 'veewom'),
'name_admin_bar' => __('Course', 'veewom'),
'add_new' => __('Add New Course', 'veewom'),
'add_new_item' => __('Add New Course', 'veewom'),
'edit_item' => __('Edit Course', 'veewom'),
'view_item' => __('View Course', 'veewom'),
'all_items' => __('All Courses', 'veewom'),
'search_items' => __('Search Courses', 'veewom'),
'not_found' => __('No courses found.', 'veewom')
);
$args = array(
'label' => __('Course', 'veewom'),
'description' => __('University Degree and Certificate Courses', 'veewom'),
'labels' => $labels,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'revisions'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-learn-more',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true, // CRITICAL: Enables Modern Gutenberg Editor & REST API!
'rewrite' => array('slug' => 'courses', 'with_front' => false)
);
register_post_type('course', $args);
}
| Argument Parameter | Default | Why It Matters |
|---|---|---|
'public' => true |
false |
Controls whether the post type is visible in administrative UI, search queries, and accessible on the frontend via public URLs. |
'has_archive' => true |
false |
Automatically creates a public post type archive page at example.com/courses/ utilizing archive-course.php. |
'show_in_rest' => true |
false |
Mandatory for modern Gutenberg! If set to false, WordPress falls back to the legacy Classic Editor for this CPT and excludes it from the WP REST API. |
'menu_icon' |
Pin icon | Defines the visual icon in the wp-admin sidebar using official WordPress Dashicons (e.g. dashicons-portfolio, dashicons-book). |
In lab exams, students register a CPT, add a new course, click "View Course", and get hit with an immediate 404 Not Found error! Why? Because WordPress has not re-written its permalink cache. The solution: Go to Settings > Permalinks and click "Save Changes" to flush rewrite rules. Developers can also call flush_rewrite_rules() upon plugin activation.
Expand your CMS mastery by studying these tightly integrated WordPress development topics:
Attach hierarchical and non-hierarchical taxonomies to your CPT.
Add structured metadata fields like prices, dates, and locations to CPTs.
Structure single-{post_type}.php and archive-{post_type}.php files.
Query and loop through custom post types with tailored arguments.