编辑: 找到了一个可行的解决方案,但它涉及将 ACF 中的一些核心文件编辑为 RESTAPI 插件,请参见此处:
https://github.com/airesvsg/acf-to-rest-api/issues/141
研究:
https://github.com/airesvsg/acf-to-rest-api-example/issues/1(我尝试了这个 Github 链接中的所有解决方案都无济于事。)
我用的是ACF Pro 6.1.4版和WP 6.2版,都是最新的
主题行说明了一切,但这里有一些更多的细节:
下面的示例 Javascript 代码。请注意,我可以毫无问题地更新电子邮件字段,但我似乎无法更新分配给用户的 ACF 字段。 (我需要大声笑。)
谢谢!
fetch("http://xxxx.xxx/wp-json/wp/v2/users/5", {
method: "POST",
headers: {
"Authorization": "Basic " + btoa(username + ':' + application_password),
"Content-Type": "application/json",
},
body: JSON.stringify({
email: "[email protected]",
fields: {
test_user_field: '5555'
}
})
})
.then(response => response.json())
.then(response => console.log(JSON.stringify(response)))
}