2012-03-07 69 views
0

無法獲取字段更新與我提供的值...有什麼不對?所有創建的自定義字段,我看到他們...只是沒有插入。使用Types插件創建字段,這就是爲什麼有一個wpcf前綴。WordPress的update_post_field不起作用

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'); 

回答

0

從快看API文檔的假設,嘗試使用$ POST_ID作爲函數的第一個參數,而不是使用全球$後

function set_ll($post_id) { 
    // global $post; 
    // $post_id = $post->ID; 
    $post = get_post($post_id);