I've been following a tutorial by Steve Marks which goes throught adding information from posts to a new Database Table
as well as the usual postmeta
one. However no matter what I try, It will not store the information in the new table, can anyone see where I'm going wrong?
Tutorial is available here: http://biostall.com/performing-a-radial-search-with-wp_query-in-wordpress
my post type is festival-event
and i made the names of my custom post types the same as in the function to see if I was missing something there.
The SQL
I used to creat the table in the db was:
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;
And the function in my functions.php
file is:
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' );
I've been researching load on what the problem could be but no luck whatsoever, I'm really stuck. Attached is images of PHPMyAdmin so you can see the db
if ( 'location' != $_POST['festival-event'] )
should beif ( 'festival-event' != $_POST['post_type'] )