Created
October 30, 2014 12:40
-
-
Save tivnet/f4ed6b0c9ef0bb9a4a23 to your computer and use it in GitHub Desktop.
SearchWP - preserve posts_per_page and offset from original wp query
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
diff -rupN /tmp/searchwp/includes/class.search.php app/plugins/searchwp/includes/class.search.php | |
--- /tmp/searchwp/includes/class.search.php 2014-09-29 15:37:54.000000000 +0300 | |
+++ app/plugins/searchwp/includes/class.search.php 2014-10-29 14:46:00.003012356 +0200 | |
@@ -284,6 +284,13 @@ class SearchWPSearch { | |
$this->order = $args['order']; | |
$this->load_posts = is_bool( $args['load_posts'] ) ? $args['load_posts'] : true; | |
+ /** CHANGES BEGIN: | |
+ Check for offset argument, this allows more precise navigation */ | |
+ if( isset( $args['offset'] ) && !empty( $args['offset'] ) ) { | |
+ $this->offset = absint( $args['offset'] ); | |
+ } | |
+ /** CHANGES END. */ | |
+ | |
// perform our query | |
$this->posts = $this->query(); | |
@@ -1837,7 +1844,12 @@ class SearchWPSearch { | |
$this->sql .= $this->postStatusLimiterSQL( $this->engineSettings ); | |
$modifier = ( $this->postsPer < 1 ) ? 1 : $this->postsPer; // if posts_per_page is -1 there's no offset | |
- $start = intval( ( $this->page - 1 ) * $modifier ); | |
+ /** CHANGES BEGIN: | |
+ Handle offset parameter */ | |
+ $start = isset( $this->offset ) ? $this->offset : intval( ( $this->page - 1 ) * $modifier ); | |
+ /** | |
+ $start = intval( ( $this->page - 1 ) * $modifier ); | |
+ CHANGES END */ | |
$total = intval( $this->postsPer ); | |
$order = $this->order; | |
diff -rupN /tmp/searchwp/searchwp.php app/plugins/searchwp/searchwp.php | |
--- /tmp/searchwp/searchwp.php 2014-10-20 10:24:46.000000000 +0300 | |
+++ app/plugins/searchwp/searchwp.php 2014-10-29 14:46:00.003012356 +0200 | |
@@ -1778,6 +1778,18 @@ Results in this set: | |
'posts_per_page' => apply_filters( 'searchwp_posts_per_page', intval( get_option( 'posts_per_page' ) ), 'default', $terms, $wpPaged ), | |
); | |
+ /** CHANGES BEGIN: | |
+ Get posts_per_page and offset from original wp query for more precise navigation */ | |
+ if( isset( $wp_query->query_vars['posts_per_page'] ) && !empty( $wp_query->query_vars['posts_per_page'] ) ) { | |
+ $args['posts_per_page'] = $wp_query->query_vars['posts_per_page']; | |
+ } | |
+ | |
+ if( isset( $wp_query->query_vars['offset'] ) && !empty( $wp_query->query_vars['offset'] ) ) { | |
+ $args['offset'] = $wp_query->query_vars['offset']; | |
+ } | |
+ /** CHANGES END. */ | |
+ | |
+ | |
// perform the search | |
$profiler = array( 'before' => microtime() ); | |
$searchwp = new SearchWPSearch( $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment