LESSON 01 / 04

Custom Post Types & Taxonomies

Add your own kinds of content — events, recipes, projects — and your own ways to group them, like "cuisine" or "event type".

🎓Mediumlevel
⏱️40 minto finish
✏️1activities

📂 Content & Data🏷️ WordPress

🎯 By the end of this lesson you can…

  • Register a custom post type
  • Register a custom taxonomy
  • Flush rewrite rules on activation
🔌 WordPress PHP events.php 👆 Tap a line to explain it
1<?php2add_action( 'init', function () {3    register_post_type( 'event', [4        'labels'       => [ 'name' => 'Events', 'singular_name' => 'Event' ],5        'public'       => true,6        'has_archive'  => true,7        'show_in_rest' => true,8        'menu_icon'    => 'dashicons-calendar',9        'supports'     => [ 'title', 'editor', 'thumbnail', 'excerpt' ],10        'rewrite'      => [ 'slug' => 'events' ],11    ] );12    register_taxonomy( 'event_type', 'event', [13        'labels'       => [ 'name' => 'Event types' ],14        'hierarchical' => true,15        'show_in_rest' => true,16    ] );17} );18do_action( 'init' );19var_dump( post_type_exists( 'event' ) );
💡 Concept check
Your events don’t show the block editor. Which argument is missing?

📌 Key takeaways

  • register_post_type( 'event', $args ) on the init hook.
  • 'show_in_rest' => true enables the block editor and REST API.
  • register_taxonomy( 'event_type', 'event', $args ) groups them.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.