2017-02-03 32 views
1

我正在構建一個帶有Listify主題的網站,我想爲自己的地圖標記添加自定義信息。 (http://fclibero.com/listings/WordPress:在函數中使用get_post_meta

我可以利用此功能添加東西的地圖標記:

function custom_listify_listing_data($data) { 
    $data[ 'date_added' ] = get_post()->post_date; 
    return $data; 
} 
add_filter('listify_listing_data', 'custom_listify_listing_data'); 

查看原始

但我需要的數據是在post_meta,這就是所謂geolocation_lat和geolocation_long。我假設我需要使用此功能:https://developer.wordpress.org/reference/functions/get_post_meta/

如何組合這兩個函數以從我的數據庫中獲取緯度和經度?

謝謝!

+0

你有沒有想從地址緯度和經度? –

回答

1

看起來這可以爲你工作:

function custom_listify_listing_data($data) { 
    $postObject = get_post(); 
    $data[ 'date_added' ] = $postObject->post_date; 
    // geolocation_lat and geolocation_long 
    $data[ 'geolocation_lat' ] = get_post_meta($postObject->ID, 'geolocation_lat', true); 
    $data[ 'geolocation_long' ] = get_post_meta($postObject->ID, 'geolocation_long', true); 
    return $data; 
} 
add_filter('listify_listing_data', 'custom_listify_listing_data'); 
+1

謝謝!完美的作品! – polonium

相關問題