Link to WPGraphQL on Github
Link to WPGraphQL on WordPress.org

Recipes: Custom Fields

Add Edit Link to All Post Types

The following snippet shows how to add the “Edit” link as a GraphQL field to all post types:

Custom FieldsCustom Post TypesPosts

Add field to output URLs for Sitemap

The following code is an example of how you can create a field called allUrls that will output site URLs that could be used to generate a sitemap.

Register GraphQL Field with Argument

This is an example of registering a field with an argument showing how to use the argument in a resolver.

Register field as a list of strings

The below code registers a field called listOfStrings that returns a list of strings as the result:

Register object and field for custom list of users

The following code creates an object type called StuntPerformer and creates a field on the RootQuery called stuntPerformers that returns a custom list of users.

List of Key Values

This is an example showing how to return a list of keys and values where the keys and values are both strings.

Add Primary Category field for The SEO Framework plugin

The following adds a field called primaryCat field when using The SEO Framework WordPress Plugin

Add field for unencoded content

The following adds a field to the NodeWithContentEditor interface to get the unencoded content for a post: