Display Post Meta Values in Arrays

I have a following function:

function frontend_add_age_group_field ( $fields ) {
  $fields['event']['event_age_group'] = array(
    'label'       => __( 'Age Group', 'event_manager' ),
    'type'        => 'multiselect',
    'options'  => array(    
                'kids' => __( 'Kids (7-10 Years)', 'wp-event-manager' ),
                'youngsters' => __( 'Youngsters (10-14 Years)', 'wp-event-manager' ),
                'youth' => __( 'Youth (15-25)', 'wp-event-manager' ),
                'adults' => __( 'Adults (25+)', 'wp-event-manager' ),
             ),
    'required'    => true,
    'priority'    => 4,
  );
  return $fields;
}

For instance, the values in the database against a post are:

a:3:{i:0;s:10:"youngsters";i:1;s:5:"youth";i:2;s:6:"adults";}

I am trying to retrieve these values on front-end which I am unable to get using this function. I am getting Nothing as an output:

function get_event_age_group()
{
    global $post;

    $data = get_post_meta( $post->ID, '_event_age_group' );
    $age_groups = $data['options'];
    return $age_groups; 

}

Can anyone help why I am unable to get the data? Thanks

Read more here: Display Post Meta Values in Arrays

Leave a Reply

Your email address will not be published. Required fields are marked *