Can't get the fields to update with values i'm providing... what's wrong? Custom fields all all created and I see them... just not getting inserted. Using Types plugin to create fields, that's why there's a wpcf prefix.
function get_data($url) {
$ch = curl_init();
$timeout = 10;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function get_cords($input) {
$url = 'http://geocoder.ca/?locate='.urlencode($input).'&geoit=xml';
$get = get_data($url);
$result = xml2array($get);
return $result;
}
function set_ll() {
global $post;
$post_id = $post->ID;
if ($post->post_type == 'dealer') {
$dealer = array();
$dealer['city'] = get_post_meta($post->ID, 'wpcf-city', true);
$dealer['pro'] = get_post_meta($post->ID, 'wpcf-pro', true);
$dealer['pc'] = get_post_meta($post->ID, 'wpcf-pc', true);
$dealer['address'] = get_post_meta($post->ID, 'wpcf-address', true);
$dealer['full'] = $dealer['address'] . ', ' . $dealer['city'] . ', ' . $dealer['pc'] . ', ' . $dealer['pc'];
$dealer['longlatt'] = get_cords($dealer['full']);
if (update_post_meta($post_id, 'wpcf-longitude', $dealer['longlatt']['geodata']['longt'])) {
update_post_meta($post_id, 'wpcf-latitude', $dealer['longlatt']['geodata']['longt']);
}
}
}
add_action('save_post', 'set_ll');
as an assumption from quickly looking at the API docs, try using $post_id as your function's first parameter instead of using global $post
function set_ll($post_id) {
// global $post;
// $post_id = $post->ID;
$post = get_post($post_id);