Hey Guys,
first never ever seen such great plugin like yours! thumbup.
Second, I hope this is the right section otherwise sorry and move 🙂
I’m trying to do a get request while pre_save_post. Sometimes it works, mosttime not.
Some src:
function my_pre_save_post( $post_id )
{
if($post_id !== 'new_post')
{
return $post_id;
}
$title = $_POST['fields']['field_5984a6941d5e9'];
$post = array(
'ID' => $title,
'post_status' => 'publish',
'post_type' => 'kunden_type',
'post_title' => $title,
);
$post_id = wp_insert_post($post);
$data = sanitize_title($_POST['fields']['field_5984a79b1d5ee']) . "+" . $_POST['fields']['field_598e3e3921695'] . "+" . $_POST['fields']['field_5984b0661d5ef'];
$baseurl = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $data;
$response = wp_remote_get($baseurl, array('timeout' => 5));
if($response['response']['code'] == 200)
{
$api_response = json_decode(wp_remote_retrieve_body($response), true);
update_field('field_59905f6f6027d', $api_response['results'][0]['geometry']['location']['lat'], $post_id);
update_field('field_599060066027e', $api_response['results'][0]['geometry']['location']['lng'], $post_id);
}
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geoloc = json_decode(curl_exec($ch), true);
*/
return $post_id;
}
I also tryed curl but its the same result.
If it fails(?) no post created
If it succeded a post created and lat /lng are placed
Is it cause some async stuff?