# How to get custom field on single event page

> Read Modern Events Calendar event custom fields with get_post_meta and display them in your single event template.

Source: https://webnus.net/dox/modern-events-calendar/how-to-get-custom-field-on-single-event-page/
Last updated: 2026-08-26

In this article, you will learn How to get custom field on [single event page](https://mec.webnus.net/events/how-to-turn-negotiations-into-success/). The event custom fields data is stored in [WordPress](https://webnus.net/dox/modern-events-calendar/what-are-the-best-php-settings-for-wordpress/) meta, and you can access them using the get\_post\_meta function. Please check the following code.

## Get custom field on single event page {#Get\_custom\_field\_on\_single\_event\_page}

```php
$event_id = get_the_ID(); // Or you can get it from request parameters
$data = get_post_meta($event_id, 'mec_fields', true);
print_r($data); // Temporarily print the data to see it
```

## Fields configuration {#Fields\_configuration}

You also need the Fields configuration

```php
$main = MEC::getInstance('app.libraries.main');

$fields = $main->get_event_fields();
if(!is_array($fields) ) $fields = array();

print_r($fields); // Temporarily print the configuration to see the structure
```

Having both $fields and $data, you can print all the fields (or your desired fields) in the output. Check the following code.

```php
foreach($fields as $field_id => $item) {
   // Not a field
   if(!is_numeric($field_id)) continue;

   // Only display desired fields
   if(!in_array($field_id, [1,2,3])) continue;

   // Field Data
   $result = isset($data[$field_id]) ? $data[$field_id] : NULL;

   // Empty Value
   if((!is_array($result) and trim($result) == '') or (is_array($result) and !count($result))) continue;

   $type = isset($item['type']) ? $item['type'] : 'text';

   if(isset($field['label'])) {
      echo '<span class="mec-event-data-field-name">'.esc_html__(stripslashes($field['label']), 'mec').': </span>';
   }

   if($type === 'email') {
      echo '<span class="mec-event-data-field-value"><a href="mailto:'.esc_attr($value).'">'.esc_html($value).'</a></span>';
   } elseif($type === 'tel') {
      echo '<span class="mec-event-data-field-value"><a href="tel:'.esc_attr($value).'">'.esc_html($value).'</a></span>';
   } elseif($type === 'url') {
      echo '<span class="mec-event-data-field-value"><a href="'.esc_url($value).'" target="_blank">'.esc_html($value).'</a></span>';
   } elseif($type === 'date') {
      $value = $main->to_standard_date($value);
      echo '<span class="mec-event-data-field-value">'.esc_html($this->main->date_i18n($date_format, strtotime($value))).'</span>';
   } elseif($type === 'textarea') {
      echo '<span class="mec-event-data-field-value">'.wpautop(stripslashes($value)).'</span>';
   } else {
      echo '<span class="mec-event-data-field-value">'.(is_array($value) ? esc_html(stripslashes(implode(', ', $value))) :
   esc_html(stripslashes($value))).'</span>';
   }
}
```
