| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- // include('formats.php');
-
- class Make_Search_Endpoint extends WP_REST_Controller {
- /**
- * Register the routes for the objects of the controller.
- */
- public function register_custom_route($route) {
- $version = '2';
- $namespace = 'craft/v' . $version;
-
- register_rest_route( $namespace, '/' . $route, [
- array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_all_items' )
- ),
- ]);
- }
- public function get_all_items( $request ) {
- $args = array(
- 'numberposts' => 9,
- );
- $params = $request->get_params();
- if($params['s']) {
- $args['s'] = $params['s'];
- }
- // https://www.relevanssi.com/user-manual/functions/relevanssi_do_query/
- $q = new WP_Query( $args );
- relevanssi_do_query( $q );
- $found_posts = $q->get_posts();
-
- return new WP_REST_Response( $found_posts, 200 );
- }
- }
-
- ?>
|