This repository was archived by the owner on Jan 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,20 @@ class Pagination implements \ArrayAccess, \JsonSerializable
88{
99 public $ items ;
1010
11- public function __construct ($ items )
11+ protected $ query ;
12+
13+ public function __construct ($ items , $ query )
1214 {
1315 $ this ->items = $ items ;
16+ $ this ->query = $ query ;
1417 }
1518
1619 public function paginate ($ args = [])
1720 {
18- return paginate_links ($ args );
21+ return paginate_links (array_merge ([
22+ 'total ' => $ this ->query ->max_num_pages ,
23+ 'current ' => get_query_var ('paged ' ) ?: 1
24+ ], $ args ));
1925 }
2026
2127 public function toArray ()
Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ class QueryBuilder
1111 *
1212 * @var array
1313 */
14- protected $ arguments = [];
14+ protected $ arguments = [
15+ 'suppress_filters ' => false
16+ ];
1517
1618 /**
1719 * Meta query arguments
@@ -96,12 +98,13 @@ public function paginate($limit = null)
9698
9799 $ this ->setArgument ('posts_per_page ' , $ limit );
98100 $ this ->setArgument ('paged ' , get_query_var ('paged ' ) ?: 1 );
101+ $ query = new \WP_Query ($ this ->getArguments ());
99102
100- foreach ((array ) get_posts ( $ this -> getArguments () ) as $ post ) {
103+ foreach ((array ) $ query -> get_posts ( ) as $ post ) {
101104 $ posts [] = $ this ->buildItem ($ post );
102105 }
103106
104- return new Pagination ($ posts );
107+ return new Pagination ($ posts, $ query );
105108 }
106109
107110 public function limit ($ limit )
@@ -194,9 +197,9 @@ protected function buildMetaWhere($args)
194197 $ value = count ($ args ) == 3 ? $ args [2 ] : $ args [1 ];
195198
196199 $ this ->metaArguments [] = [
197- 'meta_key ' => $ key ,
198- 'meta_value ' => $ value ,
199- 'meta_compare ' => $ compare
200+ 'key ' => $ key ,
201+ 'value ' => $ value ,
202+ 'compare ' => $ compare
200203 ];
201204
202205 return $ this ;
You can’t perform that action at this time.
0 commit comments