我试图查询我在管理端设置的ACF选项页字段,并通过WP API使用GatsbyJS的gatsby-source-wordpress
查询它们。当我运行build和dev时,它会请求数据并打印输出
=== [ Fetching wordpress__acf_options ] === http://url.local/wp-json/acf/v3/options/options/
⠈ source and transform nodes -> wordpress__acf_options fetched : 1
Fetching the wordpress__acf_options took: 518.885ms
=== [ Fetching wordpress__acf_options ] === http://url.local/wp-json/acf/v3/options/options
⠈ source and transform nodes -> wordpress__acf_options fetched : 1
Fetching the wordpress__acf_options took: 478.580ms
,然后在浏览器中的这些URL中,得到此响应。所以我知道数据是正确的
{
acf: {
social_options: [
{
social_name: "Twitter ",
social_link: "https://twitter.com"
},
{
social_name: "Linkedin",
social_link: "https://www.linkedin.com/"
}
],
test: "pagfe 1"
}
}
问题是当我在内部GraphQL中查询allWordpressAcfOptions
时。我尝试看看可以查询哪些选项,但我只能得到ID
。这是我在下面的查询。
{
allWordpressAcfOptions {
edges {
node {
id
internal {
type
contentDigest
owner
}
children {
id
}
wordpress_id
}
}
}
}
,其中没有数据是我需要的数据,没有一个代表REST API链接中显示的相同数据。因此,缺少一些东西。这是我从查询中得到的响应。
{
"data": {
"allWordpressAcfOptions": {
"edges": [
{
"node": {
"id": "038ece9f-326d-5bb0-8f17-1bb72ce06c57",
"internal": {
"type": "wordpress__acf_options",
"contentDigest": "10b2729a5f87723bbafc539f99fb23d6",
"owner": "gatsby-source-wordpress"
},
"children": [],
"wordpress_id": "acf"
}
}
]
}
}
}
作为参考,我在gatsby配置中的gatsby-source-wordpress
选项如下
options: {
baseUrl: 'url.local',
protocol: 'http',
hostingWPCOM: false,
useACF: true,
acfOptionPageIds: ['options'],
verboseOutput: true
},
options
指的是我的ACF选项页在wordpress侧的functions.php中设置的页面ID。
总之,GatsbyJs正在引用API并提取数据,但是通过GraphQL查询数据我做错了什么?