0

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 screenshot of phpMyAdmin

  • var_dump( $check_link ); Is it what you expect? – shanebp Aug 21 '15 at 17:24
  • First, this line if ( 'location' != $_POST['festival-event'] ) should be if ( 'festival-event' != $_POST['post_type'] ) – czerspalace Aug 21 '15 at 18:14
  • @czerspalace That worked,how stupid of me, do you want to write it as answer and i'll mark it as correct? – Addzy Aug 24 '15 at 9:16
0

First, this line

    if ( 'location' != $_POST['festival-event'] )  

should be

    if ( 'festival-event' != $_POST['post_type'] )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.