Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register Pro Custom Fields #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions includes/types/object/class-event-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +292 to +294
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'resolve' => function ( $source ) use( $field ) {
get_post_meta( $source->ID, $field['name'], true);
}
'resolve' => static function ( $source ) use( $field ) {
return get_post_meta( $source->ID, $field['name'], true );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for a response to #30 (comment) before merging.

)
);
}
}
}
}