我正在尝试将wordpress帖子中的数据插入到新的表数据库表中,而不是WP_postmeta
. 我的函数正在运行,它将插入$postid
没问题。我遇到的问题是,我需要从Marty Spellerbergs的“地址地理编码器”插件中插入纬度和经度坐标。
在插件页面上,Marty说您可以使用以下内容访问循环中的Cooridate:
<?php echo get_geocode_lng( $post->ID ); ?>
<?php echo get_geocode_lat( $post->ID ); ?>
现在我知道在函数内部。php文件,我们实际上并不在lood中,所以我尝试了很多不同的方法来访问这些数据,但我就是做不到。是否有办法编辑Marty指定的行,以便在函数中调用它们?。这是我在这方面的多次尝试之一:
function save_lat_lng( $post_id )
{
global $wpdb;
global $post;
$custom_lat = $_POST[get_geocode_lat( $post->ID )];
$custom_lng = $_POST[get_geocode_lng( $post->ID )];
// Check that we are editing the right post type
if ( \'festival-event\' != $_POST[\'post_type\'] )
{
return;
}
// Check if we have a lat/lng stored for this property already
$check_link = $wpdb->get_row("SELECT * FROM lat_lng_post WHERE post_id = \'" . $post_id . "\'");
if ($check_link != null)
{
// We already have a lat lng for this post. Update row
$wpdb->update(
\'lat_lng_post\',
array(
"lat" => $custom_lat,
"lng" => $custom_lng
),
array( \'post_id\' => $post_id ),
array(
\'%f\',
\'%f\'
)
);
}
else
{
// We do not already have a lat lng for this post. Insert row
$wpdb->insert(
\'lat_lng_post\',
array(
\'post_id\' => $post_id,
"lat" => $custom_lat,
"lng" => $custom_lng
),
array(
\'%d\',
\'%f\',
\'%f\'
)
);
}
}
add_action( \'save_post\', \'save_lat_lng\' )