|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+// include('formats.php');
|
|
|
3
|
+
|
|
|
4
|
+class Make_Search_Endpoint extends WP_REST_Controller {
|
|
|
5
|
+ /**
|
|
|
6
|
+ * Register the routes for the objects of the controller.
|
|
|
7
|
+ */
|
|
|
8
|
+ public function register_custom_route($route) {
|
|
|
9
|
+ $version = '2';
|
|
|
10
|
+ $namespace = 'craft/v' . $version;
|
|
|
11
|
+
|
|
|
12
|
+ register_rest_route( $namespace, '/' . $route, [
|
|
|
13
|
+ array(
|
|
|
14
|
+ 'methods' => WP_REST_Server::READABLE,
|
|
|
15
|
+ 'callback' => array( $this, 'get_all_items' )
|
|
|
16
|
+ ),
|
|
|
17
|
+ ]);
|
|
|
18
|
+ }
|
|
|
19
|
+ public function get_all_items( $request ) {
|
|
|
20
|
+ $args = array(
|
|
|
21
|
+ 'numberposts' => 9,
|
|
|
22
|
+ );
|
|
|
23
|
+ $params = $request->get_params();
|
|
|
24
|
+ if($params['s']) {
|
|
|
25
|
+ $args['s'] = $params['s'];
|
|
|
26
|
+ }
|
|
|
27
|
+ // https://www.relevanssi.com/user-manual/functions/relevanssi_do_query/
|
|
|
28
|
+ $q = new WP_Query( $args );
|
|
|
29
|
+ relevanssi_do_query( $q );
|
|
|
30
|
+ $found_posts = $q->get_posts();
|
|
|
31
|
+
|
|
|
32
|
+ return new WP_REST_Response( $found_posts, 200 );
|
|
|
33
|
+ }
|
|
|
34
|
+}
|
|
|
35
|
+
|
|
|
36
|
+?>
|