Changeset 1392300
- Timestamp:
- 04/11/2016 06:25:50 PM (10 years ago)
- Location:
- rest-api-search/trunk
- Files:
-
- 2 added
- 3 edited
-
README.md (modified) (1 diff)
-
lib (added)
-
lib/class-wp-rest-search-controller.php (added)
-
readme.txt (modified) (3 diffs)
-
rest-api-search.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rest-api-search/trunk/README.md
r1389698 r1392300 1 1 # REST API Search # 2 ## This is only for Version 2 of the REST API Plugin ## 2 3 3 4 This adds the missing functionality of Search into the WordPress REST API. -
rest-api-search/trunk/readme.txt
r1389698 r1392300 5 5 Requires at least: 4.4 6 6 Tested up to: 4.4.2 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 14 14 15 15 # REST API Search # 16 ## This is only for Version 2 of the REST API Plugin ## 16 17 17 18 This adds the missing functionality of Search into the WordPress REST API. … … 67 68 * Initial Version 68 69 * Fully working version which searches all post types except revisions and types with 'exclude_from_search' set to true. 70 71 = 1.1 = 72 * Restructured code to allow for custom fields added in by other plugins -
rest-api-search/trunk/rest-api-search.php
r1389698 r1392300 4 4 Plugin URI: https://github.com/KCPT19/REST-API-Search 5 5 Description: Adds in the missing search functionality of all post types to the REST API v2 plugin. 6 Version: 1. 06 Version: 1.1 7 7 Author: KCPT 8 8 Author URI: https://github.com/orgs/KCPT19 … … 16 16 { 17 17 18 protected $posts; 19 18 20 public function __construct() 19 21 { 20 22 21 add_action( 'rest_api_init', array( $this, 'restAPI' ) );23 add_action( 'rest_api_init', array( $this, 'restAPI' ), 100 ); 22 24 23 25 } … … 26 28 { 27 29 28 register_rest_route( 'wp/v2', '/search/(?P<search>[a-zA-Z+]*)[/]*(?P<page>\d*)', array( 29 'methods' => 'GET', 30 'callback' => array( $this, 'search'), 31 'args' => array( 32 'class' => array( 33 'default' => 'col-md-4' 34 ), 35 's' => false 36 ), 37 )); 30 require_once dirname( __FILE__ ) . '/lib/class-wp-rest-search-controller.php'; 31 32 $this->controller = new WP_REST_Search_Controller(); 33 $this->controller->register_routes(); 38 34 39 35 } 40 36 41 public function search( WP_REST_Request $request )42 {43 44 $search = $request->get_param( 'search' );45 $page = $request->get_param( 'page' );46 47 if( empty( $page ) )48 $page = 1;49 50 $page = intval( $page );51 52 $search = implode( ' ', explode( "+", $search ) );53 54 $posts = get_posts(array(55 'page' => $page,56 'post_type' => 'any',57 'posts_per_page' => 10,58 's' => $search59 ));60 61 return $posts;62 63 }64 37 65 38 }
Note: See TracChangeset
for help on using the changeset viewer.