通过 REST API(前端)在 Wordpress 自定义 post 类型中插入 ACF 数据
Insert ACF data in Wordpress custom post type through REST API (front-end)
我的目标是能够使用 javascript 提取方法插入数据。
插入 post 非常有效,
但我只能插入 post title 和 status。
如何插入 ACF 数据?
fetch('http://mywebsite.com.br/wp-json/wp/v2/athletes/',{
method: "POST",
headers:{
'Content-Type': 'application/json',
'accept': 'application/json',
'Authorization': `Bearer ${this.state.userToken}`
},
body:JSON.stringify({
title: 'my custom post title',
status: 'publish',
acf: {
my_field: 'my acf value here'
}
})
}).then( (response) => {
return response.json();
}).then( (post) => {
console.log(post);
});
发现了!
在这里回答:
我只需要更改对象内“字段”的“acf”。
我的目标是能够使用 javascript 提取方法插入数据。
插入 post 非常有效, 但我只能插入 post title 和 status。 如何插入 ACF 数据?
fetch('http://mywebsite.com.br/wp-json/wp/v2/athletes/',{
method: "POST",
headers:{
'Content-Type': 'application/json',
'accept': 'application/json',
'Authorization': `Bearer ${this.state.userToken}`
},
body:JSON.stringify({
title: 'my custom post title',
status: 'publish',
acf: {
my_field: 'my acf value here'
}
})
}).then( (response) => {
return response.json();
}).then( (post) => {
console.log(post);
});
发现了!
在这里回答:
我只需要更改对象内“字段”的“acf”。