GithubHelp home page GithubHelp logo

aleufroy / rest-api-filter-fields Goto Github PK

View Code? Open in Web Editor NEW

This project forked from svrooij/rest-api-filter-fields

0.0 2.0 0.0 7 KB

Filter the fields returned by the Wordpress rest api (v2)

License: MIT License

JavaScript 20.79% PHP 79.21%

rest-api-filter-fields's Introduction

REST API - Filter Fields

Contributors: svrooij
Donate link: https://svrooij.nl/buy-me-a-beer
Tags: json, rest, api, rest-api
Requires at least: 4.3
Tested up to: 4.4
Stable tag: 1.0.1
License: MIT
License URI: https://raw.githubusercontent.com/svrooij/rest-api-filter-fields/master/LICENSE

Filter the properties returned by the wordpress rest api V2

Description

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, 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,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

Installation

Installing this plugin is really easy.

  1. Upload rest-api-filter-fields.php to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress

You can also download it through the build-in plugin manager. Then it will be installed in /wp-content/plugins/rest-api-filter-fields/.

Frequently Asked Questions

Does this also work for my custom posttype?

Yes, we picked 20 as priority (default = 10) for activating. This mean this plugin is probably activated last, so all custom post types should already be loaded.

I found a bug, what should I do?

All the bugs/issues are maintained on github.com/svrooij/rest-api-filter-fields so please create an issue (or a pull request with a fix there)

Changelog

1.0.1

  • Bumped tested wordpress version to 4.4
  • Metadata update (personal website is https only :D)

1.0.0

  • First release of rest-api-filter-fields

rest-api-filter-fields's People

Contributors

svrooij avatar

Watchers

James Cloos avatar leufroy avatar

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.