diff --git a/wire/core/PageFinder.php b/wire/core/PageFinder.php index 35c53aca..538e091f 100644 --- a/wire/core/PageFinder.php +++ b/wire/core/PageFinder.php @@ -1728,6 +1728,7 @@ class PageFinder extends Wire { $joinType = 'join'; if(count($fields) > 1 + || !empty($options['startAfterID']) || !empty($options['stopBeforeID']) || (count($valueArray) > 1 && $numEmptyValues > 0) || ($subfield == 'count' && !$this->isRepeaterFieldtype($field->type)) || ($selector->not && $selector->operator != '!=') @@ -1796,6 +1797,17 @@ class PageFinder extends Wire { $this->getQuerySortSelector($query, $s); } } + + if((!empty($options['startAfterID']) || !empty($options['stopBeforeID'])) && count($query->where)) { + $wheres = array('(' . implode(' AND ', $query->where) . ')'); + $query->set('where', array()); + foreach(array('startAfterID', 'stopBeforeID') as $key) { + if(empty($options[$key])) continue; + $bindKey = $query->bindValueGetKey($options[$key], \PDO::PARAM_INT); + array_unshift($wheres, "pages.id=$bindKey"); + } + $query->where(implode("\n OR ", $wheres)); + } $this->postProcessQuery($query); $this->finalSelectors = $selectors; diff --git a/wire/core/PageTraversal.php b/wire/core/PageTraversal.php index 5554d537..90ea86f6 100644 --- a/wire/core/PageTraversal.php +++ b/wire/core/PageTraversal.php @@ -327,8 +327,11 @@ class PageTraversal { } if(!$options['until']) return $fo; - - // all code below this specific to the 'until' option + + /*************************************************************** + * All code below this specific to the 'until' option + * + */ $until = $options['until']; /** @var string $until */ @@ -352,7 +355,8 @@ class PageTraversal { } else { // selector string - $stopPage = $page->_pages('find', "$selector, limit=1, $until")->first(); + $findOptions = $options['prev'] ? array() : array('startAfterID' => $page->id); + $stopPage = $page->_pages('find', "$selector, limit=1, $until", $findOptions)->first(); } if($stopPage && $stopPage->id) {