1

i want to update my acf field present in a page using REST API, how can i do that, it is very difficult to me as i searched everywhere but didnt get my answer

1 Answer 1

1

I had the same problem and sticked together this javascript-code from various sources, which works great now:

      const username = 'your_wp_username'
      const pass = 'your_wp_appliaction_password'
      const token = window.btoa(`${username}:${pass}`)
      const url = 'https://yoururl.com/wp-json/acf/v3/projects/384?fields[title]=Better title';
      const params = {
        'cache': 'no-cache',
        'method': 'PATCH',
        'credentials': 'omit',
        'headers': {
          'Authorization': `Basic ${token}`,
          'Content-Type': 'application/json; charset=UTF-8; application/x-www-form-urlencoded',
        },
      }
      fetch(url,params)
      .then((res) => {
        return res.json();
      })
      .then((data) => {
        console.log(data)
      })

Make sure to replace the following variables in my code:

your_wp_username
You can find your wordpress-username in: WP-Backend --> User --> Edit

your_wp_application_password
You can generate an Application Specific Password in: WP-Backend --> User --> Edit --> Scroll to the bottom or by following this guide. The password will look something like this: XXXX XXXX XXXX XXXX XXXX XXXX

your_url

  • Make sure to change the url https://yoururl.com/wp-json/acf/v3/projects/ to your custom API endpoint.
  • The number 384 after the endpoint is the ID of the element / post we're updating in this request
  • The word title in the url is the fieldname we're updating
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.