From f81ebc88a1046b99253d508527e7881cd45cb3be Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Tue, 25 Feb 2014 20:26:59 -0700 Subject: [PATCH] Adding offset support to searcher for pagination --- classes/simplemap.php | 2 ++ classes/xml-search.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/simplemap.php b/classes/simplemap.php index c49818b..274d6b8 100644 --- a/classes/simplemap.php +++ b/classes/simplemap.php @@ -1084,6 +1084,7 @@ if ( !class_exists( 'Simple_Map' ) ) { } var bounds = new google.maps.LatLngBounds(); + //- CALL TO RENDER EACH LOCATION markers.each( function () { var locationData = this; locationData.distance = parseFloat(locationData.distance); @@ -1390,6 +1391,7 @@ if ( !class_exists( 'Simple_Map' ) ) { return marker; } + //- FUNCTION THAT GENERATES LIST ITEMS function createSidebarEntry(marker, locationData, searchData) { var div = document.createElement('div'); diff --git a/classes/xml-search.php b/classes/xml-search.php index 4221e18..b10d0d1 100644 --- a/classes/xml-search.php +++ b/classes/xml-search.php @@ -25,6 +25,7 @@ if ( !class_exists( 'SM_XML_Search' ) ){ 'onlyzip' => false, 'country' => false, 'limit' => false, + 'page' => false, 'pid' => 0, ); $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 ); + + if ( $input['page'] && $input['page'] < 250 ) + $offset = 'OFFSET ' . ( absint($input['page']) - 1) * $limit; + else + $offset = ''; + // 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_order = 'distance, '; @@ -108,7 +115,7 @@ if ( !class_exists( 'SM_XML_Search' ) ){ GROUP BY posts.ID $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 );