0

My goal is to be able to insert data using JavaScript fetch method.

Inserting the post worked like a charm, but I can only insert the post title and status. How can I insert ACF data?

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);
});
1
  • @Sohrab my attempt is javascript only. Commented Nov 18, 2020 at 2:18

1 Answer 1

1

found out! answer here: Populate ACF Fields using Wordpress Rest API JS

I just had to change "acf" for "fields" inside the object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.