首页 > 解决方案 > WordPress 盖茨比

问题描述

我正在将 Gatsby 与 Wordpress 一起使用。我根据文档设置了所有内容。

但是当我去 Graphql 查询资源管理器(可以生成 graphql 查询)时,没有与 Wordpress 相关的查询。错误是:

无法在查询类型上查询字段 allWordpressPost。

我也安装了“gatsby-source-wordpress”模块。

这是我的 global.config.js 代码:

module.exports = {  siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,  },
plugins: [
`gatsby-plugin-react-helmet`,
{
    resolve: `gatsby-source-wordpress`,
    options: {
        // Specify the URL of the WordPress source
        baseUrl: `example.com`,
        protocol: `https`,
        // Indicates if a site is hosted on WordPress.com
        hostingWPCOM: false,
        // Specify which URL structures to fetch
        includedRoutes: [
          '**/posts',
          '**/tags',
          '**/categories'
        ]
    }
},
{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `images`,
    path: `${__dirname}/src/images`,
  },
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
  resolve: `gatsby-plugin-manifest`,
  options: {
    name: `gatsby-starter-default`,
    short_name: `starter`,
    start_url: `/`,
    background_color: `#663399`,
    theme_color: `#663399`,
    display: `minimal-ui`,
    icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
  },
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}

标签: phpwordpressgraphqlgatsby

解决方案


您是否安装并启用了必要的 Wordpress 插件来启用 graphql(WPGraphQL、WPGatsby)?查看官方文档中的步骤。对我来说工作得很好。

考虑使用这个启动器,而不是自己设置。


推荐阅读