1. 13
    Add a Custom Post Type to the GraphQL Headless WordPress API Endpoint
    1m 40s

Add a Custom Post Type to the GraphQL Headless WordPress API Endpoint

Share this video with your friends

Send Tweet

In this lesson, we will expose a Custom Post Type to the graphQL layer. This would normally be done in the Custom Post Type Plugin UI but if you browse the options you'll notice that there is no setting for GraphQL. This means we will need to write a custom function that exposes our user-created post type.

We will use add_filter in our headless.php file to expose the chairs post type. The filter we'll use is register_post_type_args. There are three fields that need to explicitly declared: show_in_graphql, graphql_single_name, graphql_plural_name.

~ 3 years ago

CPT UI is now provided with a field that allows the post to be shown in Graphql

Kevin Cunninghaminstructor
~ 2 years ago

CPT UI does indeed allow you to add to GraphQL within it's settings menu. Like in code, you have to make available and set the names (singular and plural).

Screenshot of CPT UI settings for this post type