REST API – Filter Fields

Filter the properties returned by the wordpress rest api V2

Author:Stephan van Rooij (profile at wordpress.org)
WordPress version required:4.4
WordPress version tested:5.4.4
Plugin version:1.0.8
Added to WordPress repository:29-10-2015
Last updated:29-06-2020
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:100
Rated by:10
Plugin URI:https://github.com/svrooij/rest-api-filter-fi...
Total downloads:32 347
Active installs:700+
plugin download
Click to start download

Since wordpress version 4.9.? wordpress includes the functionality provided by this plugin in the core of wordpress.

Checkout https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields for functionality included in the wordpress core,
they made it even better by filtering the amount of data pulled from the database.

This plugin will no longer be maintained since it has been superseded by the core functionality.

The wp-rest-api-v2 returns a lot of properties.
It could be very useful (or mobile-data-friendly) to only return the properties needed by the application.

If you only want titles and links of some articles it doesn’t make sense to return the content or the excerpt.

This isn’t limited to posts, it also works on custom posttypes, categories, pages, terms, taxonomies and comments.

Instead of returning:

{
  "id": 2138,
  "date": "2015-10-25T15:31:03",
  "guid": {
    "rendered": "http://worldofict.nl/?p=2138"
  },
  "modified": "2015-10-25T15:31:03",
  "modified_gmt": "2015-10-25T14:31:03",
  "slug": "rechtenvrije-fotos",
  "type": "post",
  "link": "http://worldofict.nl/tip/2138-rechtenvrije-fotos/",
  "title": {
    "rendered": "Rechtenvrije foto’s"
  },
  "content": {
    "rendered": ".. A lot of content .. "
  },
  "excerpt": {
    "rendered": " .. A lot of content ..."
  },
  "author": 2,
  "featured_image": 2139,
  "comment_status": "open",
  "ping_status": "open",
  "sticky": false,
  "format": "standard",
  //.. even more tags ....
}

It can return (with fields=id,title.rendered,link as GET parameter)

{
  "id": 2138,
  "link": "http://worldofict.nl/tip/2138-rechtenvrije-fotos/",
  "title": {
    "rendered": "Rechtenvrije foto’s"
  }
}

Notes

  1. If you specify fields so it wouldn’t return data the default response is send back to the client.
  2. (for developers) something wrong with this plugin? Github
  3. If you liked the plugin consider sponsoring me