2012-03-07 77 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);