Code Monkey home page Code Monkey logo

wp-rest-api-filter-items's Introduction

WP REST API Filter Items

Unit Tests Build Status Code Climate License

A WordPress plugin to filters WordPress REST API items for your request. Its removing key and values 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 currently supports 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 ready and open for feature requests for the WP API Version 2.

Installation

Install static via download, clone the repository or use dependency management via Composer

composer require bueltge/wp-rest-api-filter-items

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.

wp-rest-api-filter-items's People

Contributors

bueltge avatar dnaber-de avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wp-rest-api-filter-items's Issues

Switch to Composer autoload

The plugin use currently a custom autoload and should switch to the Composer way via composer.json configuration. In this context the composer.json needs an update.

Not working in Woocommerce

Query:
site.com/wp-json/wc/v3/products?items=id,name
just outputs all fields.

This query is working:
site.com/wp-json/wp/v2/comments?items=id,author_name

Is there a way to fix it?

Examples in Readme

The current Readme shows this as an example:

Result for post, wp-json/posts?items=ID,title,content

[
  {
    "ID": 1,
    "title": "Hello world!",
    "content": "<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",
    "author": {...},
    "featured_image": null,
    "terms": {...}
  }
]

But the fields author, featured_image and terms should not appear in the example output, shouldn't they?

some help

http://localhost/wordpress/wp-json/wp/v2/posts/8095?items=_links
i am trying to get only "_links " but i get empty [] in response ,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.