I am not sure what I am doing wrong here and would appreciate the help
I have an array the looks like this:
Array
(
[85369] => 3
[85368] => 13
[85378] => 23
)
When I try to update the database with
update_post_meta( $id, 'key', $MyArr);
in the databse the array is not stored. What is stored is:
a:0:{}
Any help would be appreciated
Full Code:
function distance($lat1, $lng1, $lat2, $lng2, $unit) {
$theta = $lng1 - $lng2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if($unit == "K"){
return round ( ($miles * 1.609344) );
}elseif ($unit == "N"){
return round ( ($miles * 0.8684) );
}else{
return round ( $miles );
}
}
$MilesArray = array();
$bounding_distance = 1;
$nearbys = $wpdb->get_results(
"
SELECT *
FROM rvty_geodata
WHERE (
geo_latitude BETWEEN ($lat - $bounding_distance) AND ($lat + $bounding_distance) AND geo_longitude BETWEEN ($lng - $bounding_distance) AND ($lng + $bounding_distance)
)
"
);
foreach ($nearbys as $nearby) {
$alt_id = $nearby->post_id;
$alt_lat = $nearby->geo_latitude;
$alt_lng = $nearby->geo_longitude;
if ($rvparks->ID != $alt_id) {
$Miles = distance($lat, $lng, $alt_lat, $alt_lng, "M");
$MilesArray[$alt_id] = $Miles;
}
}
asort($MilesArray);
if(count($MilesArray)>10){
$MilesArrayChunk = array_chunk($MilesArray, 10, true);
$ALTCGArray = $MilesArrayChunk[0];
}else{
$ALTCGArray = $MilesArray;
}
update_post_meta( $rvparks_id, 'alt_camps', $ALTCGArray);
$MilesArray
variable (that it's not an empty array)?