# Events Post Type With Event Categories

> Registers an "Events" post type with featured images, an /events/ archive and an Event Category taxonomy, as the base for a simple events calendar.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: custom-post-types, events, calendar
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cpt-events/

## Code

```php
// Names used in labels and URLs: edit to suit.
$wpide_type = array(
    'name'     => 'event', // Internal name: lowercase, max 20 characters, never change it once you have content.
    'singular' => 'Event',
    'plural'   => 'Events',
    'slug'     => 'events',
);

add_action( 'init', function () use ( $wpide_type ) {
    $s = $wpide_type['singular'];
    $p = $wpide_type['plural'];

    register_post_type( $wpide_type['name'], array(
        'labels'        => array(
            'name'                  => $p,
            'singular_name'         => $s,
            'menu_name'             => $p,
            'add_new_item'          => "Add New $s",
            'edit_item'             => "Edit $s",
            'new_item'              => "New $s",
            'view_item'             => "View $s",
            'view_items'            => "View $p",
            'all_items'             => "All $p",
            'search_items'          => "Search $p",
            'not_found'             => 'Nothing found.',
            'not_found_in_trash'    => 'Nothing found in Trash.',
            'archives'              => "$s Archives",
            'attributes'            => "$s Attributes",
            'insert_into_item'      => "Insert into $s",
            'uploaded_to_this_item' => "Uploaded to this $s",
            'item_published'        => "$s published.",
            'item_updated'          => "$s updated.",
        ),
        'public'        => true,
        'has_archive'   => $wpide_type['slug'],
        'rewrite'       => array( 'slug' => $wpide_type['slug'], 'with_front' => false ),
        'show_in_rest'  => true,
        'menu_icon'     => 'dashicons-calendar-alt',
        'menu_position' => 25,
        'supports'      => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
    ) );

    register_taxonomy( 'event_category', $wpide_type['name'], array(
        'labels'            => array(
            'name'          => 'Event Categories',
            'singular_name' => 'Event Category',
            'menu_name'     => 'Event Categories',
            'all_items'     => 'All Event Categories',
            'edit_item'     => 'Edit Event Category',
            'view_item'     => 'View Event Category',
            'update_item'   => 'Update Event Category',
            'add_new_item'  => 'Add New Event Category',
            'new_item_name' => 'New Event Category Name',
            'search_items'  => 'Search Event Categories',
            'not_found'     => 'No event categories found.',
            'parent_item'   => 'Parent Event Category',
        ),
        'hierarchical'      => true,
        'public'            => true,
        'rewrite'           => array( 'slug' => 'event-category', 'with_front' => false ),
        'show_admin_column' => true,
        'show_in_rest'      => true,
    ) );
} );
```

## Notes

Do not use alongside an events plugin that already registers an "event" post type. Visit Settings > Permalinks once after activating.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Events Post Type With Event Categories" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
