Support

Account

Home Forums General Issues Updating ACF fields using cURL

Unread

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;
        }
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.