factor1 / better-rest-endpoints

A WordPress plugin that serves up slimmer WP Rest API endpoints.
https://wordpress.org/plugins/better-rest-endpoints/
GNU General Public License v3.0
67 stars 25 forks source link
api wordpress wordpress-api wordpress-plugin

better-rest-endpoints

A WordPress plugin that serves up slimmer WP Rest API endpoints.

Endpoints

Posts

better-rest-endpoints/v1/posts Gets a collection of posts. Accepts the following parameters:

It returns a JSON response with the following:

Post

better-rest-endpoints/v1/post/{id} Get a post by ID.

Accepts the following parameters:

Returns a JSON response with the following:

Post by slug

better-rest-endpoints/v1/post/{slug} Get a post by ID.

Accepts the following parameters:

Returns a JSON response with the following:

Pages

better-rest-endpoints/v1/pages Gets a collection of pages. Accepts the following parameters:

Returns the following JSON Response:

Page by ID

better-rest-endpoints/v1/page/{id} Get a page by ID.

Accepts the following parameters:

Returns a JSON response with the following:

Post by slug

better-rest-endpoints/v1/page/{slug|path} Get a page by slug or path. Requesting a page by slug will only return a page with no parent with the requested slug. If multiple pages have the same slug the page needs to be requested by passing the entire path. eg. better-rest-endpoints/v1/page/technology/about or better-rest-endpoints/v1/page/services/about instead of just better-rest-endpoints/v1/page/about

Accepts the following parameters:

Returns a JSON response with the following:

Custom Post Type Collection

better-rest-endpoints/v1/{custom_post_type} Gets a collection of posts from a custom post type. Accepts the following parameters:

Returns the following JSON response:

Custom Post Type Post by ID

better-rest-endpoints/v1/{custom_post_type}/{id} Gets a single custom post type item. Accepts the following parameters:

Returns the following JSON Response:

Custom Post Type Post by Slug

better-rest-endpoints/v1/{custom_post_type}/{slug} Gets a single custom post type item. Accepts the following parameters:

Returns the following JSON Response:

Get Posts Belonging To A Taxonomy Term

better-rest-endpoints/v1/{taxonomy}/{term} Gets posts from a taxonomy term. Accepts the following parameters:

Returns the following JSON Response:

Menus from slug (name)

better-rest-endpoints/v1/menus/{menu-slug} Gets a WordPress Menu by slug. Accepts no parameters.

Returns the following JSON Response in each item object:

Menus from location (theme location)

better-rest-endpoints/v1/menus/{menu-slug} Gets a WordPress Menu by the theme location. Accepts no parameters.

Returns an empty array if the location can not be found or if it has no assigned menu. Returns an array of the following objects if a menu is assigned to the specified location:

Taxonomies

better-rest-endpoints/v1/taxonomies Gets a list of taxonomies used by WordPress. Accepts no parameters.

Returns the following JSON response in each item object:

Search

better-rest-endpoints/v1/search Gets a collection of posts and pages based on the search parameter. Accepts the following parameters:

It returns a JSON response with the following (returns an empty array if no posts found):

ACF Options

better-rest-endpoints/v1/options/acf Gets an array of all ACF Options Page fields, returns an empty array if none are found or if ACF is not active.

better-rest-endpoints/v1/options/acf/{field} Gets a single ACF Options Page field, returns null if ACF is not active or the field does not exist.

Accepts the following parameters:

Hooks and Filters

Filter the Custom Post Types endpoints

add_filter('better_rest_endpoints_cpt_collection', function($cpt_collection){
    $cpt_collection = array_flip($cpt_collection);
    unset($cpt_collection['oembed_cache']);
    unset($cpt_collection['_pods_template']);
    unset($cpt_collection['_pods_pod']);
    unset($cpt_collection['_pods_field']);
    $cpt_collection = array_values( array_flip($cpt_collection) );
    return $cpt_collection;
});