|
|
@@ -1,4 +1,6 @@
|
|
1
|
1
|
<?php
|
|
|
2
|
+include('related-items.php');
|
|
|
3
|
+
|
|
2
|
4
|
class Make_Sort_By extends WP_REST_Controller {
|
|
3
|
5
|
private $post_type;
|
|
4
|
6
|
private $sort_type;
|
|
|
@@ -55,6 +57,10 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
55
|
57
|
);
|
|
56
|
58
|
}
|
|
57
|
59
|
|
|
|
60
|
+ if($params['episode']) {
|
|
|
61
|
+ $args['by'] = $params['episode'];
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
58
|
64
|
return $args;
|
|
59
|
65
|
}
|
|
60
|
66
|
/**
|
|
|
@@ -100,7 +106,7 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
100
|
106
|
$index_from_page = $args['page'] - 1;
|
|
101
|
107
|
$offset = array_chunk($res, $args['posts_per_page']);
|
|
102
|
108
|
$page = $offset[$index_from_page];
|
|
103
|
|
- return new WP_REST_Response( $this->prepare_items_for_reponse($page), 200 );
|
|
|
109
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($page, false), 200 );
|
|
104
|
110
|
}
|
|
105
|
111
|
|
|
106
|
112
|
public function by_material( $request ) {
|
|
|
@@ -109,8 +115,7 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
109
|
115
|
$found_posts = $q->get_posts();
|
|
110
|
116
|
wp_reset_postdata();
|
|
111
|
117
|
|
|
112
|
|
- return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
|
|
113
|
|
-
|
|
|
118
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts, false), 200 );
|
|
114
|
119
|
}
|
|
115
|
120
|
|
|
116
|
121
|
public function by_past( $request ) {
|
|
|
@@ -128,15 +133,26 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
128
|
133
|
$found_posts = $q->get_posts();
|
|
129
|
134
|
wp_reset_postdata();
|
|
130
|
135
|
|
|
131
|
|
- return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
|
|
|
136
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts, false), 200 );
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ public function by_episode( $request ) {
|
|
|
140
|
+ $q = new WP_Query($this->make_args($request, null));
|
|
|
141
|
+ // $args['max'] $q->max_num_pages;
|
|
|
142
|
+ $found_posts = $q->get_posts();
|
|
|
143
|
+ wp_reset_postdata();
|
|
|
144
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts, true), 200 );
|
|
132
|
145
|
}
|
|
133
|
146
|
|
|
134
|
|
- public function prepare_items_for_reponse( $items ) {
|
|
|
147
|
+ public function prepare_items_for_reponse( $items, $p2p ) {
|
|
135
|
148
|
$collection = [];
|
|
136
|
149
|
|
|
137
|
150
|
forEach( $items as $item ) {
|
|
138
|
151
|
$formatted = default_post_format($item, false);
|
|
139
|
152
|
$formatted[hero] = get_post_meta( $item->ID, 'hero_header', true );
|
|
|
153
|
+ if($p2p == true) {
|
|
|
154
|
+ $formatted[relatedto] = p2p_related_to( $item->ID );
|
|
|
155
|
+ }
|
|
140
|
156
|
array_push($collection, $formatted);
|
|
141
|
157
|
}
|
|
142
|
158
|
|