function send_custom_post_to_zapier($post_ID, $post, $update) {
// Check if this is the custom post type you want to send
if ($post->post_type !== ‘tip’) {
return;
}
// Get all the post data
$post_data = (array) $post;
// Get all post meta fields
$meta_data = get_post_meta($post_ID);
// Prepare an array for ACF fields if ACF is being used
$acf_data = [];
if (function_exists(‘get_fields’)) {
// This will return an array of all ACF fields with their user-friendly names
$acf_data = get_fields($post_ID);
}
// Combine post data, meta data, and ACF data
$data = array_merge($post_data, [‘meta’ => $meta_data], [‘acf’ => $acf_data]);
// Webhook URL (replace with the URL from Zapier)
$webhook_url = ‘https://hooks.zapier.com/hooks/catch/18288482/2dlst4s/’;
// Send data to Zapier
$response = wp_remote_post($webhook_url, [
‘body’ => json_encode($data),
‘headers’ => [
‘Content-Type’ => ‘application/json’
]
]);
// Debugging: Log the response from Zapier for troubleshooting
if (is_wp_error($response)) {
error_log(‘Zapier webhook error: ‘ . $response->get_error_message());
} else {
error_log(‘Zapier webhook response: ‘ . print_r($response, true));
}
}
add_action(‘save_post’, ‘send_custom_post_to_zapier’, 10, 3);