Skip to content

A WordPress plugin that filter WP REST API items to your requirement.

License

Notifications You must be signed in to change notification settings

huilang-me/wp-rest-api-filter-items

 
 

Repository files navigation

WP REST API Filter Items

Build Status Code Climate License

A WordPress plugin to filter WordPress REST API items for your request. Removing Content From WP API Response on your request.

Description

Per default, a post via WordPress REST API would fetch all data in wp-json/wp/v2/posts. For many reasons you might want to exclude certain fields from WP API response in certain circumstances. This plugin enables you to filter your request for fields you require. Add items to the GET attribute on the url, like wp-json/wp/v2/posts?items=id,title,content in order to get only according field values.

The plugin supports currently the filtering of post, taxonomy and comments.

WP-API Versions

  • Use the branch wp-api-v1 if you use WP-API Version 1.
  • The master branch is for development, currently refactoring for WP API Version 2.

Examples

Result for post: wp-json/wp/v2/posts?_wp_json_nonce=4355d0c4b3&items=id,title,content

[
	{
		"id": 1,
		"title": {
			"rendered": "Hello world!"
		},
		"content": {
			"rendered": "<p>Welcome to <a href=\"http://localhost/wpbeta/\">WP Beta Dev Sites</a>. This is your first post. Edit or delete it, then start blogging!</p>\n"
		}
	}
]

Result for taxonomy: p-json/wp/v2/taxonomies/category?_wp_json_nonce=4355d0c4b3&items=name,slug,types.

{
	"name": "Categories",
	"slug": "category",
	"types": [
		"post",
		"archiv"
	]
}

Result for comments: wp-json/wp/v2/comments?items=id,author_name

[
	{
		"id": 1,
		"author_name": "Mr WordPress"
	},
	{
		"id": 2,
		"author_name": "admin"
	}
]

Requirements

  • PHP 5.4
  • WordPress 4.*
  • WP REST API

Kudos

Thanks @dnaber-de for his modular, extendable PHP autoloader.

About

A WordPress plugin that filter WP REST API items to your requirement.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%