Support » Developing with WordPress » Save_post Doesn’t Execute from WordPress iOS App

  • Resolved mikedunn

    (@mikedunn)


    I wrote a theme function (I’m new at this) to take GPS coordinates in custom fields, pass them to the Google Maps API to get the actual location name, then put that result into another custom field. It works fine when I publish or update a post from wp-admin, but it never fires from the WordPress iOS app. (The app otherwise works fine.) Having it work from iOS is kind of important because that’s how I get the coordinates.

    I’ve tried numerous different actions (save_post, publish_post, xmlrpc_publish_post, etc.) but none of them fire. Do these actions simply not fire from the iOS app for some reason?

    /* Query Google Maps API for location name */
        function get_place_name($post_id, $post, $update) {
        $lat = get_post_meta(get_the_ID(), 'geo_latitude', true);
        $lng = get_post_meta(get_the_ID(), 'geo_longitude', true);
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($lat) . ',' . trim($lng) . '&sensor=false&key=<KEY>';
        $json = @file_get_contents($url);
        $data = json_decode($json);
        $status = $data->status;
        if ($status == "OK"){
            $long_name_1 = $data->results[0]->address_components[0]->long_name;
            $long_name_2 = $data->results[0]->address_components[1]->long_name;
            $long_name_3 = $data->results[0]->address_components[2]->long_name;
            $placename = $long_name_1 . ', ' . $long_name_2 . ', ' . $long_name_3;
            update_post_meta(get_the_ID(), 'geo_googlemapsapi_url', $url);
            update_post_meta(get_the_ID(), 'geo_place_name', $placename);}
        else {
            update_post_meta(get_the_ID(), 'geo_place_name', 'No location found');
        }
        }
        add_action('save_post', 'get_place_name', 10, 3);
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Save_post Doesn’t Execute from WordPress iOS App’ is closed to new replies.