· 5 years ago · Jun 26, 2020, 10:42 PM
1function update_imported_listing($post_id) {
2
3 $listing_details = get_field('listing_details', $post_id);
4
5 wp_update_post(array(
6 'ID' => $post_id,
7 'post_title' => $listing_details['propertytitle'],
8 'post_name' => $listing_details['propertytitle'],
9 'post_status' => 'publish'
10 ));
11
12 update_latlng($post_id, $listing_details);
13 $user_id = get_post_field('post_author', $post_id);
14
15 author_listing_count($user_id);
16 update_listing_wants_current_value('listing',$user_id);
17 listing_agents_add($post_id, $user_id);
18
19 function update_latlng($post_id, $listing_details) {
20 $lat = $listing_details['latitude'];
21 $lng = $listing_details['longitude'];
22 $city = $listing_details['city_area'];
23 $zip = $listing_details['zip'];
24 $state = $listing_details['State'];
25 $county = $listing_details['country'];
26 $country = $listing_details['country_territory'];
27 $street = $listing_details['street_number'];
28 $street_name = $listing_details['street_name'];
29 $api_key = get_option('google_maps_key');
30 if ($lat == '' || $lng == '') {
31 $lat = 0;
32 $lng = 0;
33 }
34
35 global $wpdb;
36
37 $sql = "insert into wp_lat_lng (object_id,lat,lng,location,area,county,state,zip,street,street_name,country)value(" . $object_id . "," . $lat . "," . $lng . ",Point(" . $lat . "," . $lng . "),'" . $city . "','" . $county . "','" . $state . "','" . $zip . "','" . $street . "','" . $street_name . "','" . $country . "')";
38 $result = $wpdb->query($sql);
39
40 // Get Image From Static Map Api and Save in Post Meta table
41 $staticMapImage = get_post_meta($object_id, 'listing_static_address_image', true);
42 if ($staticMapImage == '') {
43 $imgURL = 'https://maps.googleapis.com/maps/api/staticmap?center=' . $lat . ',' .
44 $lng . '&zoom=14&scale=false&size=640x640&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0xff0000%7Clabel:%7C' .
45 $lat . ',' . $lng . '&key=' . $api_key;
46
47 $imageData = base64_encode(file_get_contents($imgURL));
48 // Format the image SRC: data:image/png;base64,{data};
49 $listing_static_image = 'data:image/png;base64,' . $imageData;
50 update_post_meta($object_id, 'listing_static_address_image', $listing_static_image);
51 }
52 return $result;
53 }
54}