Skip to content

Instantly share code, notes, and snippets.

@arbaouimehdi
Created January 26, 2020 17:31
Show Gist options
  • Save arbaouimehdi/00b5a4c3151c78353cc9aa61d45b81ad to your computer and use it in GitHub Desktop.
Save arbaouimehdi/00b5a4c3151c78353cc9aa61d45b81ad to your computer and use it in GitHub Desktop.
Add a Custom Type to WordPress, and show it in GraphQL
<?php
add_action( 'init', function() {
register_post_type( 'events', [
'show_ui' => true,
'labels' => [
'menu_name' => __( 'Events', 'your-textdomain' ),//@see https://developer.wordpress.org/themes/functionality/internationalization/
],
'show_in_graphql' => true,
'hierarchical' => true,
'graphql_single_name' => 'Event',
'graphql_plural_name' => 'Events',
] );
} );
add_filter( 'register_post_type_args', function( $args, $post_type ) {
if ( 'events' === $post_type ) {
$args['show_in_graphql'] = true;
$args['graphql_single_name'] = 'Event';
$args['graphql_plural_name'] = 'Events';
}
return $args;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment