A developer’s life beyond the screen.


5. Custom Post Types and Taxonomies

Custom Post Types (CPTs) are one of the most useful features in WordPress.
If you understand how they work, you can build almost any type of website — blogs, portfolios, directories, event sites, product catalogs, and more.

In this article, we’ll explain CPTs and taxonomies in the simplest way possible so beginners can start using them confidently.


What Is a Custom Post Type?

WordPress already comes with a few post types:

  • Posts
  • Pages
  • Attachments
  • Revisions

A Custom Post Type is simply a new type of content you create yourself.

For example:

  • Movies
  • Books
  • Students
  • Testimonials
  • Events
  • Courses

Instead of putting everything inside “Posts”, CPTs let you keep content organized.


When Should You Use a CPT?

Use a CPT when the content is different from normal blog posts.

For example:

If you are building a website for a school:

  • Students → CPT
  • Teachers → CPT
  • Courses → CPT

If you are building a business website:

  • Testimonials → CPT
  • Services → CPT
  • Portfolio → CPT

CPTs help structure the content properly, especially when the project grows.


How to Create a Custom Post Type

You create a CPT using the register_post_type() function.
The best place to run this function is inside the init hook.

A simple example:

add_action('init', function () {
    register_post_type('movie', [
        'label' => 'Movies',
        'public' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-video-alt',
        'supports' => ['title', 'editor', 'thumbnail'],
    ]);
});

Now you’ll see a new “Movies” section in the WordPress admin menu.


Common Parameters Explained Simply

You don’t have to remember everything.
Just focus on the basics:

  • label → name shown in admin
  • public → whether it appears on the frontend
  • menu_icon → icon in the dashboard
  • supports → what fields it should have (title, editor, image, etc.)

As you gain experience, you can explore more advanced settings like capabilities and rewrite rules.


What Is a Taxonomy?

A taxonomy is a way to group and categorize content.
WordPress has two default taxonomies:

  • Categories
  • Tags

You can create your own taxonomies for CPTs.

Examples:

  • Movie Genres (Action, Drama, Comedy…)
  • Book Categories (Fiction, Non-Fiction…)
  • Event Types (Workshop, Webinar…)

Taxonomies help organize large sets of content.


How to Register a Custom Taxonomy

Here’s a simple example that adds “Genres” to the “Movies” CPT:

add_action('init', function () {
    register_taxonomy('genre', 'movie', [
        'label' => 'Genres',
        'public' => true,
        'hierarchical' => true,
    ]);
});

Now you can assign genres to movie posts.


Hierarchical vs Non-Hierarchical

This sounds confusing at first, but it’s easy:

  • Hierarchical = works like Categories
    You can have parent/child relationships.
  • Non-hierarchical = works like Tags
    No parent/child structure.

Choose based on how you want to organize the content.


Where CPTs and Taxonomies Are Used in Real Life

Almost every professional WordPress website uses CPTs:

  • A real estate site → Properties CPT
  • A job portal → Jobs CPT
  • A university site → Courses + Departments
  • A travel site → Destinations + Regions
  • A review site → Products + Categories
  • A portfolio site → Projects + Skills

If you learn CPTs well, you can handle most dynamic websites confidently.


Best Practices for Beginners

  • Always register CPTs inside the init hook
  • Keep CPT code inside its own file (for better organization)
  • Use meaningful names (e.g., “course”, not “cp_type_4”)
  • Use lowercase letters in CPT slugs
  • Don’t create too many CPTs unless necessary

Good structure makes development easier later.


What’s Next

In the next article, we’ll look at the WordPress REST API—a very important part of modern WordPress development.

You’ll learn:

  • How the REST API works
  • How to create your own API endpoints
  • How to secure them
  • How to use them from JavaScript or external apps