Adding offset support to searcher for pagination

This commit is contained in:
Will Bradley 2014-02-25 20:26:59 -07:00
parent 96d893fd58
commit f81ebc88a1
2 changed files with 10 additions and 1 deletions

View File

@ -1084,6 +1084,7 @@ if ( !class_exists( 'Simple_Map' ) ) {
} }
var bounds = new google.maps.LatLngBounds(); var bounds = new google.maps.LatLngBounds();
//- CALL TO RENDER EACH LOCATION
markers.each( function () { markers.each( function () {
var locationData = this; var locationData = this;
locationData.distance = parseFloat(locationData.distance); locationData.distance = parseFloat(locationData.distance);
@ -1390,6 +1391,7 @@ if ( !class_exists( 'Simple_Map' ) ) {
return marker; return marker;
} }
//- FUNCTION THAT GENERATES LIST ITEMS
function createSidebarEntry(marker, locationData, searchData) { function createSidebarEntry(marker, locationData, searchData) {
var div = document.createElement('div'); var div = document.createElement('div');

View File

@ -25,6 +25,7 @@ if ( !class_exists( 'SM_XML_Search' ) ){
'onlyzip' => false, 'onlyzip' => false,
'country' => false, 'country' => false,
'limit' => false, 'limit' => false,
'page' => false,
'pid' => 0, 'pid' => 0,
); );
$input = array_filter( array_intersect_key( $_GET, $defaults ) ) + $defaults; $input = array_filter( array_intersect_key( $_GET, $defaults ) ) + $defaults;
@ -49,6 +50,12 @@ if ( !class_exists( 'SM_XML_Search' ) ){
$limit = apply_filters( 'sm-xml-search-limit', $limit ); $limit = apply_filters( 'sm-xml-search-limit', $limit );
if ( $input['page'] && $input['page'] < 250 )
$offset = 'OFFSET ' . ( absint($input['page']) - 1) * $limit;
else
$offset = '';
// Locations within specific distance or just get them all? // Locations within specific distance or just get them all?
$distance_select = $wpdb->prepare( "( 3959 * ACOS( COS( RADIANS(%s) ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS(%s) ) + SIN( RADIANS(%s) ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance", $input['lat'], $input['lng'], $input['lat'] ) . ', '; $distance_select = $wpdb->prepare( "( 3959 * ACOS( COS( RADIANS(%s) ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS(%s) ) + SIN( RADIANS(%s) ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance", $input['lat'], $input['lng'], $input['lat'] ) . ', ';
$distance_order = 'distance, '; $distance_order = 'distance, ';
@ -108,7 +115,7 @@ if ( !class_exists( 'SM_XML_Search' ) ){
GROUP BY GROUP BY
posts.ID posts.ID
$distance_having $distance_having
ORDER BY " . apply_filters( 'sm-location-sort-order', $distance_order . ' posts.post_name ASC', $input ) . " " . $limit; ORDER BY " . apply_filters( 'sm-location-sort-order', $distance_order . ' posts.post_name ASC', $input ) . " " . $limit . " " . $offset;
$sql = apply_filters( 'sm-xml-search-locations-sql', $sql ); $sql = apply_filters( 'sm-xml-search-locations-sql', $sql );