Plugin Directory

Changeset 1392300


Ignore:
Timestamp:
04/11/2016 06:25:50 PM (10 years ago)
Author:
KCPT
Message:

Restructured whole plugin to allow for custom fields

Location:
rest-api-search/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • rest-api-search/trunk/README.md

    r1389698 r1392300  
    11# REST API Search #
     2## This is only for Version 2 of the REST API Plugin ##
    23
    34This adds the missing functionality of Search into the WordPress REST API.
  • rest-api-search/trunk/readme.txt

    r1389698 r1392300  
    55Requires at least: 4.4
    66Tested up to: 4.4.2
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414
    1515# REST API Search #
     16## This is only for Version 2 of the REST API Plugin ##
    1617
    1718This adds the missing functionality of Search into the WordPress REST API.
     
    6768* Initial Version
    6869* 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  
    44Plugin URI:  https://github.com/KCPT19/REST-API-Search
    55Description: Adds in the missing search functionality of all post types to the REST API v2 plugin.
    6 Version:     1.0
     6Version:     1.1
    77Author:      KCPT
    88Author URI:  https://github.com/orgs/KCPT19
     
    1616{
    1717
     18    protected $posts;
     19
    1820    public function __construct()
    1921    {
    2022
    21         add_action( 'rest_api_init', array( $this, 'restAPI' ) );
     23        add_action( 'rest_api_init', array( $this, 'restAPI' ), 100 );
    2224
    2325    }
     
    2628    {
    2729
    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();
    3834
    3935    }
    4036
    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' => $search
    59         ));
    60 
    61         return $posts;
    62 
    63     }
    6437
    6538}
Note: See TracChangeset for help on using the changeset viewer.