Home › Forums › General Issues › Updating ACF fields using cURL
Hello, I hope someone could please advise on the following issues. We are trying to update ACF fields using a cURL (POST) from a different domain using PHP but no fields are updating.
ACF must have this basic feature ?
Any help would be appreciated.
// continued code
if (isset($response['id'])) {
echo 'Post created successfully with ID: ' . $response['id'];
$post_id = $response['id'];
$acf_update_url = 'https://website.com/wp-json/acf/v3/vehicle/' . $post_id; // Adjust the ACF endpoint
$acf_data = array(
'fields' => array(
'status' => 'draft',
'vehicle-status' => 'AVAILABLE',
'vehicle-visibility' => 'DISPLAY',
'vehicle-make' => 'Ford',
'vehicle-model' => 'Astra',
'vehicle-colour' => 'White'
)
);
// Close the current cURL session
curl_close($ch);
// Create a new cURL session for updating ACF fields
$ch_update = curl_init();
// Set cURL options for updating ACF fields
curl_setopt($ch_update, CURLOPT_URL, $acf_update_url);
curl_setopt($ch_update, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch_update, CURLOPT_POSTFIELDS, json_encode($acf_data));
curl_setopt($ch_update, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_update, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($username . ':' . $password),
));
// Execute cURL session for updating ACF fields
$acf_result = curl_exec($ch_update);
//var_dump($acf_result);
// Check for errors in updating ACF fields
if (curl_errno($ch_update)) {
echo 'Curl error in updating ACF fields: ' . curl_error($ch_update);
} else {
echo 'ACF fields updated successfully.';
var_dump($acf_result);
echo '<br />';
var_dump($acf_data);
echo '<br />';
echo $acf_update_url;
}
// Close the cURL session for updating ACF fields
curl_close($ch_update);
} else {
echo 'Failed to create post. Response: ' . $result;
}
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.