【发布时间】:2015-11-15 15:15:52
【问题描述】:
我一直在关注 Steve Marks 的教程,该教程将帖子中的信息添加到新的 Database Table 以及通常的 postmeta 中。但是无论我尝试什么,它都不会将信息存储在新表中,任何人都可以看到我哪里出错了吗?
教程可在此处获得:http://biostall.com/performing-a-radial-search-with-wp_query-in-wordpress
我的帖子类型是festival-event,并且我将自定义帖子类型的名称与函数中的名称相同,以查看我是否在那里遗漏了什么。
我用来在数据库中创建表的SQL是:
CREATE TABLE IF NOT EXISTS `lat_lng_post` (
`post_id` bigint(20) unsigned NOT NULL,
`lat` float NOT NULL,
`lng` float NOT NULL
) ENGINE=InnoDB;
而我functions.php文件中的函数是:
function save_lat_lng( $post_id )
{
global $wpdb;
// Check that we are editing the right post type
if ( 'location' != $_POST['festival-event'] )
{
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" => $_POST['lat_field_name'],
"lng" => $_POST['lng_field_name']
),
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" => $_POST['lat_field_name'],
"lng" => $_POST['lng_field_name']
),
array(
"%d",
"%f",
"%f"
)
);
}
}
add_action( 'save_post', 'save_lat_lng' );
【问题讨论】:
-
你的帖子到达了吗,通过 isset 的测试?
-
我该如何测试呢?我的数据库知识很少,这是我唯一需要做的事情,帖子正常添加到 postmeta 表中
标签: php mysql database wordpress