Created
November 12, 2013 20:56
-
-
Save madshostrup/7438546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_cars() { | |
$ne = $_REQUEST['northeast']; | |
$sw = $_REQUEST['southwest']; | |
$args = array( | |
'post_type' => 'car', | |
'post_status' => 'publish', | |
'meta_query' => array( | |
'relation' => 'AND', | |
array( | |
'key' => 'locationlat', | |
'value' => array($sw[0], $ne[0]), | |
'compare' => 'BETWEEN' | |
), | |
array( | |
'key' => 'locationlng', | |
'value' => array($sw[1], $ne[1]), | |
'compare' => 'BETWEEN' | |
), | |
) | |
); | |
$query = new WP_Query($args); | |
$cars_inside_bounds = []; | |
$carIds = []; | |
while ($query->have_posts()) { | |
$query->the_post(); | |
$car_info = array(get_field(CAR::LOCATIONLAT), get_field(CAR::LOCATIONLNG)); //makes location string into lat and lng array | |
$carImages = get_field(CAR::GALLERY); | |
array_push($car_info, get_the_ID()); | |
array_push($car_info, get_permalink()); | |
array_push($car_info, get_field(CAR::MODEL)); | |
array_push($car_info, get_field(CAR::RENT_PERDAY)); | |
array_push($car_info, $carImages[0]['sizes']['large']); | |
array_push($cars_inside_bounds, $car_info); | |
} | |
print_r(json_encode($cars_inside_bounds)); | |
die(); | |
} | |
add_action('wp_ajax_nopriv_get_cars', 'get_cars'); | |
add_action('wp_ajax_get_cars', 'get_cars'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment