Created
January 26, 2020 17:31
-
-
Save arbaouimehdi/00b5a4c3151c78353cc9aa61d45b81ad to your computer and use it in GitHub Desktop.
Add a Custom Type to WordPress, and show it in GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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