{"_id":"@angeloashmore/gatsby-source-wordpress","_rev":"3-febf54c7d38419511d975a950b35bdde","name":"@angeloashmore/gatsby-source-wordpress","dist-tags":{"latest":"3.0.0-beta.6"},"versions":{"2.0.84":{"name":"@angeloashmore/gatsby-source-wordpress","description":"Gatsby source plugin for building websites using the Wordpress CMS as a data source.","version":"2.0.84","author":{"name":"Sebastien Fichot","email":"fichot.sebastien@gmail.com"},"bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"bundleDependencies":false,"dependencies":{"axios":"^0.16.1","babel-runtime":"^6.26.0","better-queue":"^3.8.6","bluebird":"^3.5.0","deep-map":"^1.5.0","deep-map-keys":"^1.2.0","gatsby-source-filesystem":"^1.5.35","json-stringify-safe":"^5.0.1","lodash":"^4.17.4","minimatch":"^3.0.4","qs":"^6.4.0"},"deprecated":false,"devDependencies":{"cross-env":"^5.0.5"},"homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress#readme","keywords":["gatsby","gatsby-plugin","gatsby-source-plugin"],"license":"MIT","repository":{"type":"git","url":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress"},"scripts":{"build":"babel src --out-dir . --ignore __tests__","prepublish":"cross-env NODE_ENV=production npm run build","watch":"babel -w src --out-dir . --ignore __tests__"},"_id":"@angeloashmore/gatsby-source-wordpress@2.0.84","dist":{"shasum":"2f2e8d69d41cf06e1becae5a551d8b498ea99dff","tarball":"https://registry.npmjs.org/@angeloashmore/gatsby-source-wordpress/-/gatsby-source-wordpress-2.0.84.tgz","fileCount":12,"unpackedSize":70845,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa9N4OCRA9TVsSAnZWagAAoY8P/AwBPV/8MyGmrW9ffLWU\nIi8J+e1qmf0RKRosOUP1J3rvxl4V8+FUxKitYdEjpv14Vr0QXkNeow785ePX\ntYobefZsR7B6lXDmp8DqowaX5610IFSezJ595MOjXZSwJZOCauYgXPKeCmo4\nYu3IMiHTJNxLPUYBhS+eZr8O/YykalhfTrAjJ/c5qJdmi+uQu/w0PemScS1D\n3zsPTSOuIWQzbbj7ZpqX7+o9GN8DeApMbkrlWeaiDRMbf7RIFzmMbpiiXxJY\nzvB+/85fP9LOEF50Vr+DvxcUAOp4GLO4COGhWwaur26JTEXghpYB3/vMhnRX\n+iYqpiELLG/Zi80g87FEvf3UK67xJCBLAxVnoPWvWFmfdRn+CcGKSBKPEuzh\nRN+1TAAdaJjTnbWblWDzovX1WDVh28emlHvtmYkJo+IN3MbKfzOd8lHVANQQ\nsXk98IZNylPdR6qq4Dbv94wJLelbQeQhg07Id6bqCYQwdekWJNfGvqduG1fc\n1SphM9+F9TLcXdkduB47QOUCt6lv3Vq14z2OiIhhlgZjEPpZNUHFaWXKF713\nNVR6MLZ+Usq7afJq7Lhb7LAdxCubkH2TOaMbXT5cTxIzWO3jFBAevJyqDI6c\nhNqCIyAMTVcp88+fo8ePwxiXKFNfn8zpAWujEt1t0S2vzjKTrfKt0l/pdoQt\nViyD\r\n=HihD\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-tJWdh/OKHOP4q6RYUbVWljL0pT1jtFmM3LS1bXop7bRPhYOVhRaurVkcpwEK1bsD7cIlk5tKpJ2SWVjrJVBqqQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAZamDx2BD9phwitWr7sM0PC4WaqCnzC+3CYEPuB//oAAiEAzOmLhfc8FlO1O7kiYeR8yZsRW1g3kxvGaF2lfPU3sw8="}]},"maintainers":[{"name":"angeloashmore","email":"angeloashmore@me.com"}],"_npmUser":{"name":"angeloashmore","email":"angeloashmore@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-source-wordpress_2.0.84_1525997068800_0.3699757726632764"},"_hasShrinkwrap":false},"3.0.0-beta.6":{"name":"@angeloashmore/gatsby-source-wordpress","description":"Gatsby source plugin for building websites using the Wordpress CMS as a data source.","version":"3.0.0-beta.6","author":{"name":"Sebastien Fichot","email":"fichot.sebastien@gmail.com"},"bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"bundleDependencies":false,"dependencies":{"@babel/runtime":"7.0.0-beta.51","axios":"^0.18.0","better-queue":"^3.8.6","bluebird":"^3.5.0","deep-map":"^1.5.0","deep-map-keys":"^1.2.0","gatsby-source-filesystem":"^2.0.1-beta.3","json-stringify-safe":"^5.0.1","lodash":"^4.17.4","minimatch":"^3.0.4","qs":"^6.4.0"},"deprecated":false,"devDependencies":{"@babel/cli":"7.0.0-beta.51","@babel/core":"7.0.0-beta.51","cross-env":"^5.1.4"},"homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress#readme","keywords":["gatsby","gatsby-plugin","gatsby-source-plugin"],"license":"MIT","peerDependencies":{"gatsby":">2.0.0-alpha"},"repository":{"type":"git","url":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress"},"scripts":{"build":"babel src --out-dir . --ignore **/__tests__","prepare":"cross-env NODE_ENV=production npm run build","watch":"babel -w src --out-dir . --ignore **/__tests__"},"_id":"@angeloashmore/gatsby-source-wordpress@3.0.0-beta.6","dist":{"shasum":"633fdecdc7df550237aa83742f63986cfd378892","tarball":"https://registry.npmjs.org/@angeloashmore/gatsby-source-wordpress/-/gatsby-source-wordpress-3.0.0-beta.6.tgz","fileCount":14,"unpackedSize":63089,"integrity":"sha512-oDEK8BwUboLPoYWXwAXZsBdXhBmWEGxbwhsjKmxbOnwcT0qlfJWd82JMC61v/3+iU9eNExsil2R3uOwLqI5ryQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICnCqBLnmFQoHF8zB7X3o4zgvd1VHUSjiHmAwnsWL3URAiEA3W5OBmHSnMzjEBVkAe98L56PQwJtKAuBz2zpSwcFCXA="}]},"maintainers":[{"name":"angeloashmore","email":"angeloashmore@me.com"}],"_npmUser":{"name":"angeloashmore","email":"angeloashmore@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-source-wordpress_3.0.0-beta.6_1531292300736_0.003401539493724126"},"_hasShrinkwrap":false}},"time":{"created":"2018-05-11T00:04:28.734Z","2.0.84":"2018-05-11T00:04:28.860Z","modified":"2022-06-12T14:41:32.710Z","3.0.0-beta.6":"2018-07-11T06:58:20.857Z"},"maintainers":[{"name":"angeloashmore","email":"angeloashmore@me.com"}],"description":"Gatsby source plugin for building websites using the Wordpress CMS as a data source.","homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress#readme","keywords":["gatsby","gatsby-plugin","gatsby-source-plugin"],"repository":{"type":"git","url":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress"},"author":{"name":"Sebastien Fichot","email":"fichot.sebastien@gmail.com"},"bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"license":"MIT","readme":"# gatsby-source-wordpress\n\nSource plugin for pulling data into [Gatsby](https://github.com/gatsbyjs) from\nWordPress sites using the\n[WordPress REST API](https://developer.wordpress.org/rest-api/reference/).\n\nAn example site for this plugin is available.\n\n- [Demo](https://using-wordpress.gatsbyjs.org/)\n- [Example site source code](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-wordpress)\n\n## Features\n\n- Pulls data from self-hosted WordPress sites, hosted on wordpress.com or\n  wordpress.org\n- Should work with any number of article and post (tested on a site with 900\n  posts)\n- Can authenticate to wordpress.com's API using OAuth 2 so media can be queried\n- Easily create responsive images in Gatsby from WordPress images. See [image\n  processing](#image-processing) section.\n\n## WordPress and custom entities\n\nThis module currently pulls from WordPress the following entities:\n\n- [x] All entities are supported (posts, pages, tags, categories, media, types,\n      users, statuses, taxonomies, ...)\n- [x] Any new entity should be pulled as long the IDs are correct.\n- [x] [ACF Entities (Advanced Custom Fields)](https://www.advancedcustomfields.com/)\n- [x] Custom post types (any type you could have declared using WordPress'\n      `functions.php`)\n\nWe welcome PRs adding support for data from other plugins.\n\n## Install\n\n`npm install --save gatsby-source-wordpress`\n\n## How to use\n\n```javascript\n// In your gatsby-config.js\nplugins: [\n  /*\n   * Gatsby's data processing layer begins with “source”\n   * plugins. Here the site sources its data from Wordpress.\n   */\n  {\n    resolve: \"gatsby-source-wordpress\",\n    options: {\n      /*\n       * The base URL of the Wordpress site without the trailingslash and the protocol. This is required.\n       * Example : 'gatsbyjsexamplewordpress.wordpress.com' or 'www.example-site.com'\n       */\n      baseUrl: \"gatsbyjsexamplewordpress.wordpress.com\",\n      // The protocol. This can be http or https.\n      protocol: \"http\",\n      // Indicates whether the site is hosted on wordpress.com.\n      // If false, then the assumption is made that the site is self hosted.\n      // If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.\n      // If your site is hosted on wordpress.org, then set this to false.\n      hostingWPCOM: false,\n      // If useACF is true, then the source plugin will try to import the Wordpress ACF Plugin contents.\n      // This feature is untested for sites hosted on Wordpress.com.\n      // Defaults to true.\n      useACF: true,\n      auth: {\n        // If auth.user and auth.pass are filled, then the source plugin will be allowed\n        // to access endpoints that are protected with .htaccess.\n        htaccess_user: \"your-htaccess-username\",\n        htaccess_pass: \"your-htaccess-password\",\n        htaccess_sendImmediately: false,\n\n        // If hostingWPCOM is true then you will need to communicate with wordpress.com API\n        // in order to do that you need to create an app (of type Web) at https://developer.wordpress.com/apps/\n        // then add your clientId, clientSecret, username, and password here\n        wpcom_app_clientSecret:\n          \"NMPnXYFtj2gKas7V1kZyMxr7oLry9V5ZxIyBQGu2txjVHg0GhFz6RYcKopkHICYg\",\n        wpcom_app_clientId: \"54793\",\n        wpcom_user: \"gatsbyjswpexample@gmail.com\",\n        wpcom_pass: \"very-secured-password\",\n      },\n      // Set verboseOutput to true to display a verbose output on `npm run develop` or `npm run build`\n      // It can help you debug specific API Endpoints problems.\n      verboseOutput: false,\n      // Set how many pages are retrieved per API request.\n      perPage: 100,\n      // Search and Replace Urls across WordPress content.\n      searchAndReplaceContentUrls: {\n        sourceUrl: \"https://source-url.com\",\n        replacementUrl: \"https://replacement-url.com\",\n      },\n      // Set how many simultaneous requests are sent at once.\n      concurrentRequests: 10,\n      // Exclude specific routes using glob parameters\n      // See: https://github.com/isaacs/minimatch\n      // Example:  `[\"/*/*/comments\", \"/yoast/**\"]` will exclude routes ending in `comments` and\n      // all routes that begin with `yoast` from fetch.\n      excludedRoutes: [\"/*/*/comments\", \"/yoast/**\"],\n      // use a custom normalizer which is applied after the built-in ones.\n      normalizer: function({ entities }) {\n        return entities\n      },\n    },\n  },\n]\n```\n\n## WordPress Plugins\n\nThese plugins were tested. We welcome PRs adding support for data from other\nplugins.\n\n- [x] Custom Post Types : it will work seamlessly, no further option needs to be\n      activated. (\"Show in REST API\" setting needs to be set to true on the\n      custom post in the plugin settings for this to work. It's set to \"false\"\n      by default.)\n\n- [x] [ACF](https://www.advancedcustomfields.com/) The option `useACF: true`\n      must be activated in your site's `gatsby-config.js`.\n\n  - You must have the plugin\n    [acf-to-rest-api](https://github.com/airesvsg/acf-to-rest-api) installed in\n    WordPress.\n  - Will pull the `acf: { ... }` fields's contents from any entity which has it\n    attached (pages, posts, medias, ... you choose from in WordPress back-end\n    while creating a Group of Fields).\n  - [ACF Pro](https://www.advancedcustomfields.com/pro/) same as ACF :\n  - Will work with\n    [Flexible content](https://www.advancedcustomfields.com/resources/flexible-content/)\n    and premium stuff like that (repeater, gallery, ...).\n  - Will pull the content attached to the\n    [options page](https://www.advancedcustomfields.com/add-ons/options-page/).\n\n- [x] [WP-API-MENUS](https://wordpress.org/plugins/wp-api-menus/) which gives\n      you the menus and menu locations endpoint.\n\n- [x] [WPML-REST-API](https://github.com/shawnhooper/wpml-rest-api) which adds\n      the current locale and available translations to all post types.\n\n## How to use Gatsby with Wordpress.com hosting\n\nSet `hostingWPCOM: true`.\n\nYou will need to provide an [API\nKey](https://en.support.wordpress.com/api-keys/).\n\nNote : you don't need this for Wordpress.org hosting in which your WordPress\nwill behave like a self-hosted instance.\n\n## Test your WordPress API\n\nBefore you run your first query, ensure the WordPress JSON API is working correctly by visiting /wp-json at your WordPress install. The result should be similar to the [WordPress demo API](https://demo.wp-api.org/wp-json/).\n\nIf you see a page on your site, rather than the JSON output, check if your permalink settings are set to “Plain”. After changing this to any of the other settings, the JSON API should be accessible.\n\n## How to query\n\nYou can query nodes created from Wordpress using GraphQL like the following:\nNote : Learn to use the GraphQL tool and Ctrl+Spacebar at\n<http://localhost:3000/___graphiql> to discover the types and properties of your\nGraphQL model.\n\n### Query posts\n\n```graphql\n{\n  allWordpressPost {\n    edges {\n      node {\n        id\n        slug\n        title\n        content\n        excerpt\n        date\n        modified\n      }\n    }\n  }\n}\n```\n\n### Query pages\n\n```graphql\n{\n  allWordpressPage {\n    edges {\n      node {\n        id\n        title\n        content\n        excerpt\n        date\n        modified\n        slug\n        status\n      }\n    }\n  }\n}\n```\n\nSame thing for other type of entity (tag, media, categories, ...).\n\n### Query any other entity\n\nIn the following example, `${Manufacturer}` will be replaced by the endpoint\nprefix and `${Endpoint}` by the name of the endpoint.\n\nTo know what's what, check the URL of the endpoint. You can set `verboseOutput: true` in order to get more information of what's executed by the source plugin\nbehind the scene.\n\nFor example the following URL:\n`http://my-blog.wordpress.com/wp-json/acf/v2/options`\n\n- Manufacturer : `acf`\n- Endpoint : `options`\n- Final GraphQL Type : AllWordpressAcfOptions\n\nFor example the following URL:\n`http://my-blog.wordpress.com/wp-api-menus/v2/menu-locations`\n\n- Manufacturer : `wpapimenus`\n- Endpoint : `menulocations`\n- Final GraphQL Type : AllWordpressWpApiMenusMenuLocations\n\n```graphql\n{\n  allWordpress${Manufacturer}${Endpoint} {\n    edges {\n      node {\n        id\n       type\n        // Put your fields here\n      }\n    }\n  }\n}\n```\n\n### Query posts with the child ACF Fields Node\n\nMention the apparition of `childWordpressAcfField` in the query below :\n\n```graphql\n{\n  allWordpressPost {\n    edges {\n      node {\n        id\n        slug\n        title\n        content\n        excerpt\n        date\n        modified\n        author\n        featured_media\n        template\n        categories\n        tags\n        acf {\n         // use ___GraphiQL debugger and Ctrl+Spacebar to describe your model.\n        }\n      }\n    }\n  }\n}\n```\n\n### Query pages with the child ACF Fields Node\n\nMention the apparition of `childWordpressAcfField` in the query below :\n\n```graphql\n{\n  allWordpressPage {\n    edges {\n      node {\n        id\n        title\n        content\n        excerpt\n        date\n        modified\n        slug\n        author\n        featured_media\n        template\n        acf {\n         // use ___GraphiQL debugger and Ctrl+Spacebar to describe your model.\n        }\n      }\n    }\n  }\n}\n```\n\n### Query with ACF Flexible Content\n\nACF Flexible Content returns an array of objects with different types and are\nhandled differently than other fields.\n\nTo access those fields, instead of using their field name, you need to use\n`[field_name]_[post_type]` (if you have field named `page_builder` in\nyour WordPress pages you would need to use `page_builder_page`).\n\nTo access data stored in these fields, you need to use GraphQL\n[inline fragments](http://graphql.org/learn/queries/#inline-fragments). This\nrequire you to know types of nodes. The easiest way to get the types of nodes is to use\n`___GraphiQL` debugger and run the below query (adjust post type and field name):\n\n```graphQL\n{\n  allWordpressPage {\n    edges {\n      node {\n        title\n        acf {\n          page_builder_page {\n            __typename\n          }\n        }\n      }\n    }\n  }\n}\n```\n\nWhen you have node type names, you can use them to create inline fragments.\n\nFull example:\n\n```graphQL\n{\n  allWordpressPage {\n    edges {\n      node {\n        title\n        acf {\n          page_builder_page {\n            __typename\n            ... on WordPressAcf_hero {\n              title\n              subtitle\n            }\n            ... on WordpressAcf_text {\n              text\n            }\n            ... on WordpressAcf_image {\n              image {\n                localFile {\n                  childImageSharp {\n                    fluid(maxWidth: 800) {\n                      ...GatsbyImageSharpFluid_withWebp\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n### Query posts with the WPML Fields Node\n\n```graphql\n{\n  allWordpressPost {\n    edges {\n      node {\n        id\n        slug\n        title\n        content\n        excerpt\n        date\n        modified\n        author\n        featured_media\n        template\n        categories\n        tags\n        wpml_current_locale\n        wpml_translations {\n          locale\n          wordpress_id\n          post_title\n          href\n        }\n      }\n    }\n  }\n}\n```\n\n### Query pages with the WPML Fields Node\n\n```graphql\n{\n  allWordpressPage {\n    edges {\n      node {\n        id\n        title\n        content\n        excerpt\n        date\n        modified\n        slug\n        author\n        featured_media\n        template\n        wpml_current_locale\n        wpml_translations {\n          locale\n          wordpress_id\n          post_title\n          href\n        }\n      }\n    }\n  }\n}\n```\n\n## Image processing\n\nTo use image processing you need `gatsby-transformer-sharp`, `gatsby-plugin-sharp` and their\ndependencies `gatsby-image` and `gatsby-source-filesystem` in your `gatsby-config.js`.\n\nYou can apply image processing to:\n\n- featured images (also known as post thumbnails),\n- ACF fields:\n  - Image field type (return value must be set to `Image Object` or `Image URL` or field name must be `featured_media`),\n  - Gallery field type.\n\nImage processing of inline images added in wordpress WYSIWIG editor is\ncurrently not supported.\n\nTo access image processing in your queries you need to use this pattern:\n\n```\n{\n  imageFieldName {\n    localFile {\n      childImageSharp {\n        ...ImageFragment\n      }\n    }\n  }\n}\n```\n\nFull example:\n\n```graphql\n{\n  allWordpressPost {\n    edges {\n      node {\n        title\n        featured_media {\n          localFile {\n            childImageSharp {\n              fixed(width: 500, height: 300) {\n                ...GatsbyImageSharpFixed_withWebp\n              }\n            }\n          }\n        }\n        acf {\n          image {\n            localFile {\n              childImageSharp {\n                fluid(maxWidth: 500) {\n                  ...GatsbyImageSharpFluid_withWebp\n                }\n              }\n            }\n          }\n          gallery {\n            localFile {\n              childImageSharp {\n                resize(width: 180, height: 180) {\n                  src\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n```\n\nTo learn more about image processing check\n\n- documentation of [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/),\n- source code of [image processing example\n  site](https://github.com/gatsbyjs/gatsby/tree/master/examples/image-processing).\n\n## Using a custom normalizer\n\nThe plugin uses the concept of normalizers to transform the json data from WordPress into\nGraphQL nodes. You can extend the normalizers by passing a custom function to your `gatsby-config.js`.\n\n### Example:\n\nYou have a custom post type `movie` and a related custom taxonomy `genre` in your WordPress site. Since\n`gatsby-source-wordpress` doesn't know about the relation of the two, we can build an additional normalizer function to map the movie GraphQL nodes to the genre nodes:\n\n```javascript\nfunction mapMoviesToGenres({ entities }) {\n  const genres = entities.filter(e => e.__type === `wordpress__wp_genre`)\n\n  return entities.map(e => {\n    if (e.__type === `wordpress__wp_movie`) {\n      let hasGenres = e.genres && Array.isArray(e.genres) && e.categories.length\n      // Replace genres with links to their nodes.\n      if (hasGenres) {\n        e.genres___NODE = e.genres.map(\n          c => genres.find(gObj => c === gObj.wordpress_id).id\n        )\n        delete e.genres\n      }\n    }\n    return e\n  })\n\n  return entities\n}\n```\n\nIn your `gatsby-config.js` you can then pass the function to the plugin options:\n\n```javascript\nmodule.exports = {\n  plugins: [\n    {\n      resolve: \"gatsby-source-wordpress\",\n      options: {\n        // ...\n        normalizer: mapMoviesToGenres,\n      },\n    },\n  ],\n}\n```\n\nNext to the entities, the object passed to the custom normalizer function also contains other helpful Gatsby functions\nand also your `wordpress-source-plugin` options from `gatsby-config.js`. To learn more about the passed object see the [source code](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress/src/gatsby-node.js).\n\n## Site's `gatsby-node.js` example\n\n```javascript\nconst _ = require(`lodash`)\nconst Promise = require(`bluebird`)\nconst path = require(`path`)\nconst slash = require(`slash`)\n\n// Implement the Gatsby API “createPages”. This is\n// called after the Gatsby bootstrap is finished so you have\n// access to any information necessary to programmatically\n// create pages.\n// Will create pages for WordPress pages (route : /{slug})\n// Will create pages for WordPress posts (route : /post/{slug})\nexports.createPages = ({ graphql, actions }) => {\n  const { createPage } = actions\n  return new Promise((resolve, reject) => {\n    // The “graphql” function allows us to run arbitrary\n    // queries against the local WordPress graphql schema. Think of\n    // it like the site has a built-in database constructed\n    // from the fetched data that you can run queries against.\n\n    // ==== PAGES (WORDPRESS NATIVE) ====\n    graphql(\n      `\n        {\n          allWordpressPage {\n            edges {\n              node {\n                id\n                slug\n                status\n                template\n              }\n            }\n          }\n        }\n      `\n    )\n      .then(result => {\n        if (result.errors) {\n          console.log(result.errors)\n          reject(result.errors)\n        }\n\n        // Create Page pages.\n        const pageTemplate = path.resolve(\"./src/templates/page.js\")\n        // We want to create a detailed page for each\n        // page node. We'll just use the WordPress Slug for the slug.\n        // The Page ID is prefixed with 'PAGE_'\n        _.each(result.data.allWordpressPage.edges, edge => {\n          // Gatsby uses Redux to manage its internal state.\n          // Plugins and sites can use functions like \"createPage\"\n          // to interact with Gatsby.\n          createPage({\n            // Each page is required to have a `path` as well\n            // as a template component. The `context` is\n            // optional but is often necessary so the template\n            // can query data specific to each page.\n            path: `/${edge.node.slug}/`,\n            component: slash(pageTemplate),\n            context: {\n              id: edge.node.id,\n            },\n          })\n        })\n      })\n      // ==== END PAGES ====\n\n      // ==== POSTS (WORDPRESS NATIVE AND ACF) ====\n      .then(() => {\n        graphql(\n          `\n            {\n              allWordpressPost {\n                edges {\n                  node {\n                    id\n                    slug\n                    status\n                    template\n                    format\n                  }\n                }\n              }\n            }\n          `\n        ).then(result => {\n          if (result.errors) {\n            console.log(result.errors)\n            reject(result.errors)\n          }\n          const postTemplate = path.resolve(\"./src/templates/post.js\")\n          // We want to create a detailed page for each\n          // post node. We'll just use the WordPress Slug for the slug.\n          // The Post ID is prefixed with 'POST_'\n          _.each(result.data.allWordpressPost.edges, edge => {\n            createPage({\n              path: `/${edge.node.slug}/`,\n              component: slash(postTemplate),\n              context: {\n                id: edge.node.id,\n              },\n            })\n          })\n          resolve()\n        })\n      })\n    // ==== END POSTS ====\n  })\n}\n```\n\n## Troubleshooting\n\n### GraphQL Error - Unknown Field on ACF\n\nACF 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}`.\n\nTo solve this, you can use the [acf/format_value filter](https://www.advancedcustomfields.com/resources/acf-format_value/). There are 2 possible ways to use this:\n\n- `acf/format_value` – filter for every field\n- `acf/format_value/type={$field_type}` – filter for a specific field based on it’s type\n\nUsing the following function, you can check for an empty field and if it's empty return `null`.\n\n```php\nif (!function_exists('acf_nullify_empty')) {\n    /**\n     * Return `null` if an empty value is returned from ACF.\n     *\n     * @param mixed $value\n     * @param mixed $post_id\n     * @param array $field\n     *\n     * @return mixed\n     */\n    function acf_nullify_empty($value, $post_id, $field) {\n        if (empty($value)) {\n            return null;\n        }\n        return $value;\n    }\n}\n```\n\nYou can then apply this function to all ACF fields using the following code snippet:\n\n```php\nadd_filter('acf/format_value', 'acf_nullify_empty', 100, 3);\n```\n\nOr if you would prefer to target specific fields, you can use the `acf/format_value/type={$field_type}` filter. Here are some examples:\n\n```php\nadd_filter('acf/format_value/type=image', 'acf_nullify_empty', 100, 3);\nadd_filter('acf/format_value/type=gallery', 'acf_nullify_empty', 100, 3);\nadd_filter('acf/format_value/type=repeater', 'acf_nullify_empty', 100, 3);\n```\n\nThis code should be added as a plugin (recommended), or within the `functions.php` of a theme.\n\n### Self-signed certificates\n\nWhen running locally, or in other situations that may involve self-signed certificates, you may run into the error: `The request failed with error code \"DEPTH_ZERO_SELF_SIGNED_CERT\"`.\n\nTo solve this, you can disable Node.js' rejection of unauthorized certificates by adding the following to `gatsby-node.js`:\n\n```javascript\nprocess.env.NODE_TLS_REJECT_UNAUTHORIZED = \"0\"\n```\n","readmeFilename":"README.md"}