fbpx

How can we help?

Adding a country field for events

WP Event Manager tutorial shows how to add country field based on Event Submission Form Fields doc and resulting in it on a single event listing.

Add the field to the frontend

In order to add fields on the front end event submission form, one needs to make changes in the PHP file.

  1. Open your theme functions.php field.
  2. Create a function , to append a new field to the events section. First hook it in:
    add_filter( 'submit_event_form_fields', 'frontend_add_country_field' );
  3. Add the code :
    <?php
    function frontend_add_country_field( $fields ) {
      $fields['event']['event_country'] = array(
        'label'       => __( 'Country ($)', 'event_manager' ),
        'type'        => 'text',
        'required'    => true,
        'placeholder' => 'e.g. germmany'
      );
      return $fields;
    }
    ?>
    

This adds an event text field at the bottom of the events form that has the label “Country”, is required, and has no placeholder.

Fields added using the above code will be saved to the event listing automatically.

Add the field to admin Meta box

In order to add a field to the Admin meta box, follow the steps:

  1. Open your theme functions.php field.
  2. Hook in your custom function in theme functions.php,
    add_filter( 'event_manager_event_listing_data_fields', 'admin_add_country_field' );

Next add your custom function:

<?php
function admin_add_country_field( $fields ) {
  $fields['_event_country'] = array(
    'label'       => __( 'Country ($)', 'event_manager' ),
    'type'        => 'text',
    'placeholder' => 'e.g. germmany',
    'description' => ''
  );
  return $fields;
}
?>

This add a text field to the admin meta box named “country”.

Note, the field name is prepended with a ‘_’. This is because the Event Manager makes your new fields hidden meta by prepending them with an underscore. This is normal.

Was this article helpful?
How can we improve this article?
Quick Links