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.


    • Related Articles

    • Event Fields

      Event Submission Form Custom Fields Settings The field editor sub-menu under Event Listings (WP Admin>> Event Manager >> Field Editor) offers flexibility to edit field labels including Type of data, description, placeholder and more. The settings ...
    • Validate submit event field Snippets

      Validation refers to the process of checking the accuracy of the information provided. When an event is posted on a website, it determines the credibility of the organizer. Hence it becomes of utmost importance to provide the details accurately. The ...
    • Venue Fields

      The Venue section in the Field Editor page (WP admin >> Event Manager >> Field Editor) displays the fields and collects the details of the Venue in the submission form. How to add a new Venue field to the venue submission form? WP Event Manager ...
    • How To Install WP Event Manager Add ons

      WP Event Manager offers a huge number of addons that help you strengthen your WordPress site with some amazing and very useful event management features and functionalities. While installing a premium addon, you need to ensure that you already have ...
    • Organizer Fields

      Organizer Fields The organizer section in the Field Editor page (WP admin>> Event Manager >> Field Editor) displays the fields and collects the details of the organizer in the submission. How to add a field to the Organizer Submission Form? WP Event ...