diff --git a/includes/types/object/class-event-type.php b/includes/types/object/class-event-type.php index cd533d9b..f7f5f6e0 100644 --- a/includes/types/object/class-event-type.php +++ b/includes/types/object/class-event-type.php @@ -271,5 +271,30 @@ function( $date ) use ( $query ) { ), ) ); + + + /** + * Register custom meta fields. + */ + $custom_fields = tribe_get_option( 'custom-fields' ); + + if ( is_array( $custom_fields ) ) { + foreach ( $custom_fields as $field ) { + // Use label as graphQL key, instead of _ecp_custom_{#}. + $key = 'custom' . ( str_replace( ' ', '', ucwords( $field['label'] ) ) ); + + register_graphql_field( + 'Event', + $key, + array( + 'type' => 'String', + 'description' => $field['label'], + 'resolve' => function ( $source ) use( $field ) { + get_post_meta( $source->ID, $field['name'], true); + } + ) + ); + } + } } }