How to display additional custom fields on a single event page?

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:

  1. Open your theme functions.php field.
  2. Create a function, to add a new field. Then, hook it in:
  3. Add the following code:
  1. /**
  2.  * get_event_start_date function.
  3.  *
  4.  * @access public
  5.  * @param int $post (default: null)
  6.  * @return string
  7.  */
  8. function get_event_YOUR_CUSTOM_FIELD_NAME( $post = null )
  9. {  
  10.     $post = get_post( $post );  
  11.     if ( $post->post_type !== 'event_listing' )
  12.         return '';    
  13.     $event_FIELD_NAME   = $post->_YOUR_CUSTOM_FIELD_NAME;  
  14.     return apply_filters( 'display_event_FIELD_NAME', $event_FIELD_NAME, $post );
  15. }
  16. /**
  17.  * Display or retrieve the current event custom field.
  18.  *
  19.  * @access public
  20.  * @param mixed $id (default: null)
  21.  * @return void
  22.  */
  23. function display_event_YOUR_CUSTOM_FIELD_NAME( $before = '', $after = '', $echo = true, $post = null )
  24. {
  25. $event_CUSTOM_FIELD_NAME = get_event_YOUR_CUSTOM_FIELD_NAME( $post );
  26. $event_CUSTOM_FIELD_NAME = $before . $event_CUSTOM_FIELD_NAME . $after;
  27. if ( $echo )
  28. echo $event_CUSTOM_FIELD_NAME;
  29. else
  30.     return $event_CUSTOM_FIELD_NAME;
  31. }

    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.

  1. display_event_YOUR_CUSTOM_FIELD_NAME( '',   '',   true, $post);

Note: Please replace CUSTOM_FIELD_NAME with the name of the field you want to display.