|
|
@@ -22,6 +22,7 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
22
|
22
|
'callback' => array( $this, 'get_all_items' )
|
|
23
|
23
|
),
|
|
24
|
24
|
]);
|
|
|
25
|
+
|
|
25
|
26
|
register_rest_route( $namespace, '/' . $route . '/(?P<id>[\d]+)', [
|
|
26
|
27
|
array(
|
|
27
|
28
|
'methods' => WP_REST_Server::READABLE,
|
|
|
@@ -61,7 +62,6 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
61
|
62
|
|
|
62
|
63
|
return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
|
|
63
|
64
|
}
|
|
64
|
|
-
|
|
65
|
65
|
public function prepare_single_item_for_response( $args ) {
|
|
66
|
66
|
$collection = array();
|
|
67
|
67
|
|
|
|
@@ -93,9 +93,11 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
93
|
93
|
}
|
|
94
|
94
|
public function prepare_all_items_for_response( $args ) {
|
|
95
|
95
|
$collection = array();
|
|
96
|
|
-
|
|
|
96
|
+
|
|
97
|
97
|
// https://developer.wordpress.org/reference/functions/get_posts/
|
|
98
|
98
|
foreach( get_posts($args) as $item ) {
|
|
|
99
|
+ // print_r($args);
|
|
|
100
|
+ // print_r($item);
|
|
99
|
101
|
$filtered = default_post_format( $item, true );
|
|
100
|
102
|
|
|
101
|
103
|
// For your hero URL
|
|
|
@@ -106,7 +108,14 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
106
|
108
|
|
|
107
|
109
|
// $filtered[relatedto] = p2p_related_to( $item->ID, $item->post_type );
|
|
108
|
110
|
|
|
109
|
|
- $collection[$item->ID] = $filtered;
|
|
|
111
|
+ if($item->post_type == 'page') {
|
|
|
112
|
+ $filtered[content] = $item->post_content;
|
|
|
113
|
+ $collection[$item->post_name] = $filtered;
|
|
|
114
|
+ }
|
|
|
115
|
+ else {
|
|
|
116
|
+ $collection[$item->ID] = $filtered;
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
110
|
119
|
}
|
|
111
|
120
|
wp_reset_postdata();
|
|
112
|
121
|
|