> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.webnus.net/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to get custom field on single event page

In this article, you will learn How to get custom field on [single event page](https://webnus.net/modern-events-calendar/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

$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

You also need the Fields configuration

$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.

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>';
   }
}