簡體   English   中英

WordPress:在函數中使用 get_post_meta

[英]WordPress: use get_post_meta in function

我正在使用 Listify 主題構建一個網站,並且我想將自定義信息添加到我的地圖標記中。 ( http://fclibero.com/listings/ )

我可以使用此函數向地圖標記添加內容:

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/

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

謝謝!

看起來這對你有用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM