How can we help?
How to display additional custom fields on a single event page?
This WP Event Manager tutorial shows you how you can add the custom event fields to a single event page.
It requires customizing your PHP file.
Display additional custom fields on a single event page
To display additional custom fields on a single event page, you need to follow the below-mentioned steps:
- Open your theme functions.php field.
- Create a function, to add a new field. Then, hook it in:
- Add the following code:
/** * get_event_start_date function. * * @access public * @param int $post (default: null) * @return string */ function get_event_YOUR_CUSTOM_FIELD_NAME( $post = null ) { $post = get_post( $post ); if ( $post->post_type !== 'event_listing' ) return ''; $event_FIELD_NAME = $post->_YOUR_CUSTOM_FIELD_NAME; return apply_filters( 'display_event_FIELD_NAME', $event_FIELD_NAME, $post ); } /** * Display or retrieve the current event custom field. * * @access public * @param mixed $id (default: null) * @return void */ function display_event_YOUR_CUSTOM_FIELD_NAME( $before = '', $after = '', $echo = true, $post = null ) { $event_CUSTOM_FIELD_NAME = get_event_YOUR_CUSTOM_FIELD_NAME( $post ); $event_CUSTOM_FIELD_NAME = $before . $event_CUSTOM_FIELD_NAME . $after; if ( $echo ) echo $event_CUSTOM_FIELD_NAME; else return $event_CUSTOM_FIELD_NAME; }
After adding the above-mentioned function, you need to override the template file named “content-single-event_listing.php” in your child theme by following this doc and adding the below mentioned function to the file.
display_event_YOUR_CUSTOM_FIELD_NAME( '', '', true, $post);
Note: Please replace CUSTOM_FIELD_NAME with the name of the field you want to display.