EE4 Custom Post Types
Any requests to get_posts of type ‘espresso_events’ or ‘espresso_venues’ automatically have an attached EE_Event or EE_Venue object, which contains extra info (like extra Event metadata, or Venue location data), and also has functions for easily getting related data.
For example, the EE_Event object has functions like is_active() (determines if the event is considered “Active” or not, taking into account the event’s status, whether all the datetimes for the event have passed, and other factors), tickets() (which retrieves all the non-archived tickets for that event), datetimes_ordered() (which retrieves all the datetimes for the event, ordered by time), etc. (See core/db_classes/EE_Event.class.php).
“Event CPT” data includes normal post data including:
- Title
- Description
- Tags
- Categories
- Featured Image
- Commenting
- Excerpt
- Custom Fields
- Slug
- Author
Taxonomies for events and venues
The espresso_event_categories
custom taxonomy is registered for events.
The espresso_venue_categories
custom taxonomy is registered for venues.
The post_tag taxonomy is also available to be used with Event Espresso events and venues.
How to change the “events” CPT slug
You can change the events slug by setting the Event Slug option in Event Espresso > Events > Templates. The slug option cannot be set to be event
, which is the singular slug of the event custom post type.
How to change the “venues” CPT slug
<?php //* Please do NOT include the opening php tag, except of course if you're starting with a blank file // change the post type slug URL to be "locations" add_filter( 'FHEE__EE_Register_CPTs__register_CPT__rewrite', 'my_custom_venue_slug', 10, 2 ); function my_custom_venue_slug( $slug, $post_type ) { if ( $post_type == 'espresso_venues' ) { $custom_slug = array( 'slug' => 'locations' ); return $custom_slug; } return $slug; }
Visit the row on Git: https://gist.github.com/joshfeck/212a67e1227fa874630c#file-ee_venues-php
You can add the above to a functions plugin or into your WordPress theme’s functions.php file.
How to change the template for the single event post
The WordPress template hierarchy will look for a single-espresso_events.php template before falling back to single.php, then singular.php, then finally to index.php.
You can set up a custom template design for the single event view by following these 3 steps:
1) Make a copy of the theme’s page.php or the single.php template and put the copy into the active WordPress child theme.
2) Rename the copy to be single-espresso_events.php.
3) Important: You will also need to add this line of code to your theme’s functions.php file:
add_filter( 'FHEE__EED_Event_Single__template_include__allow_custom_selected_template', '__return_true' );
How to change the template for the event list archive
The <a href="https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-post-types">WordPress template hierarchy</a> will look for a archive-espresso_events.php template before falling back to archive.php, then finally to index.php.<br> You can set up a custom template design for the <strong>event list archive</strong> by following these 3 steps:<br> 1) <strong>Make a copy</strong> of the theme’s archive.php or the index.php template and put the copy into the active WordPress child theme.<br> 2) <strong>Rename</strong> the copy to be archive-espresso_events.php.<br> 3) <strong>Important:</strong> You will also need to add this line of code to your theme’s functions.php file:
add_filter( 'FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', '__return_true' );
Please be sure to <a href="https://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme">set up a child theme</a> before you begin to make theme modifications. When you keep your modifications within the child theme, your changes will not be overwritten should the theme need to be updated in the future.
How to change the Archive titles for EE custom post type archives
If your WordPress theme uses <a href="https://developer.wordpress.org/reference/functions/the_archive_title/">the_archive_title()</a> to display the archive title, you can change the post type archive titles by adding the following code to the theme’s functions.php file or add to a site specific functions plugin:
<?php //* Please do NOT include the opening php tag, except of course if you're starting with a blank file function my_theme_ee_archive_titles( $title ) { if ( is_post_type_archive('espresso_events') ) { $title = 'Upcoming Events'; } elseif ( is_post_type_archive('espresso_venues') ) { $title = 'Locations'; } elseif ( is_post_type_archive('espresso_people') ) { $title = 'Staff'; } return $title; } add_filter( 'get_the_archive_title', 'my_theme_ee_archive_titles' );
Visit the row on Git: https://gist.github.com/joshfeck/5244f2e9685b17013122cd2a81a7efa8#file-ee_get_the_archive_title-php