Custom post type registration and management for Data Machine Events with selective taxonomy menu control and custom admin columns for event date display and sorting.
The Event_Post_Type class handles the complete registration and management of the data_machine_events custom post type. It provides enhanced admin interface features including custom columns for event dates, selective taxonomy menu control, and proper menu highlighting.
inc/Core/Event_Post_Type.php
- Registers
data_machine_eventspost type with full WordPress features - Supports all standard post features (title, editor, excerpt, thumbnail, etc.)
- REST API enabled with custom controller
- Publicly queryable with custom rewrite slug
/events
- Custom Date Column: Displays event date and time in admin post list
- Sortable Date Column: Allows sorting events by date in admin
- Selective Taxonomy Menus: Controls which taxonomies appear in admin menus
- Menu Highlighting: Proper menu highlighting for allowed taxonomies
POST_TYPE:'data_machine_events'- The post type slug
Main registration method that sets up the post type and all admin hooks.
Adds the "Event Date" column to the admin posts list.
Renders the event date in the custom column, showing formatted date and time.
Makes the event date column sortable in the admin interface.
Handles the actual sorting by event date when the column header is clicked.
Manages which taxonomy menus are displayed in the admin, based on the data_machine_events_post_type_menu_items filter.
The class provides selective control over which taxonomies appear in the admin menu for the events post type. By default, only venue and promoter taxonomies are shown, with settings as an additional menu item.
This is controlled via the data_machine_events_post_type_menu_items filter:
add_filter('data_machine_events_post_type_menu_items', function($items) {
return [
'venue' => true,
'promoter' => true,
'settings' => true
];
});- Event Dates Sync: Works with
event-dates-sync.phpfor automatic datetime synchronization to thedatamachine_event_datestable - Taxonomies: Integrates with
Venue_TaxonomyandPromoter_Taxonomy - Blocks: Supports Event Details and Calendar blocks
- REST API: Provides REST endpoints for the post type
The custom event date column shows:
- Formatted date (M j, Y format)
- Formatted time (g:i a format)
- "No date set" message when no datetime is available
- "Invalid date" message for malformed dates
array(
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'events'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'supports' => array(
'title', 'editor', 'excerpt', 'thumbnail',
'custom-fields', 'revisions', 'author',
'page-attributes', 'editor-styles',
'wp-block-styles', 'align-wide'
),
'show_in_rest' => true,
'menu_icon' => 'dashicons-calendar-alt'
)