From f7987b72918e8ab50a955ea3adcd151ab1096417 Mon Sep 17 00:00:00 2001 From: Kevin McAloon Date: Fri, 31 May 2019 09:07:17 -0400 Subject: [PATCH] docs(gatsby-source-wordpress): Clarify how to retrieve post meta (#13929) * Updated docs to clarify how to retrieve post meta Docs were a little unclear as to how to interact with post meta fields. See #13883. * chore: format * Revised bullets & added troubleshooting link * chore: format --- packages/gatsby-source-wordpress/README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-wordpress/README.md b/packages/gatsby-source-wordpress/README.md index edfc737d506aa..8f45bc0dbd4eb 100644 --- a/packages/gatsby-source-wordpress/README.md +++ b/packages/gatsby-source-wordpress/README.md @@ -25,11 +25,13 @@ This module currently pulls the following entities from WordPress: users, statuses, taxonomies, site metadata, ...) - [x] Any new entity should be pulled as long as the IDs are correct. - [x] [ACF Entities (Advanced Custom Fields)](https://www.advancedcustomfields.com/) -- [x] Custom post types (any type you could have declared using WordPress' - `functions.php`) +- [x] Custom Post Types (any type you could have registered and enabled in the REST API) +- [x] Post Meta (any meta fields you could have registered and enabled in the REST API) We welcome PRs adding support for data from other plugins. +Note : If some fields are missing, check [troubleshooting missing fields](#missing-fields) section. + ## Install `npm install --save gatsby-source-wordpress` @@ -878,6 +880,18 @@ exports.createPages = async ({ graphql, actions }) => { ## Troubleshooting +### Missing Fields + +If you have custom post types or metadata that are not showing up within the schema, make sure that they are enabled within the REST API. + +- **Custom Meta** + + To retrieve custom post meta in your queries, they first must be registered using WordPress' `register_meta()` function with `show_in_rest` set as `true`. You will then see your registered post meta in your Gatsby GraphQL Schema nested within the `meta` field for associated entities. For more details, see https://developer.wordpress.org/reference/functions/register_meta/. + +- **Custom Post Types** + + If you are programmatically registering post types with `register_post_type()` and would like to use them in your queries, make sure to have `show_in_rest` set as `true`. Otherwise if you are using a plugin such as CPT UI to register your custom post types, check your configurations to make sure that the post types you want to query are enabled to show in REST API. + ### GraphQL Error - Unknown Field on ACF ACF returns `false` in cases where there is no data to be returned. This can cause conflicting data types in GraphQL and often leads to the error: `GraphQL Error Unknown field {field} on type {type}`.