Este plugin no se ha probado con las últimas 3 versiones mayores de WordPress. Puede que ya no tenga asistencia ni lo mantenga nadie, o puede que tenga problemas de compatibilidad cuando se usa con las versiones más recientes de WordPress.

REST API – Filter Fields

Descripción

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"
  }
}

Notas

  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

Instalación

Installing this plugin is really easy.

Just search the plugin directory for rest api filter fields and press install.
Or download it right from Github and copy the rest-api-filter-fields directory in the archive to wp-content/plugins/.

Preguntas frecuentes

Do you add data to the response?

No, this plugin only removes entries.
When you want to add featured_images, I recommend using better-rest-api-featured-images

How about nested propterties?

You can filter on nested properties with a ‘.’ like ‘title.rendered’. Not sure if this also works on arrays. Existing issues or Submit issue

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.
But this only works if you made it public for the api.
See Adding REST API Support for Custom Content Types for more information.

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.

Reseñas

10 de junio de 2018
Thank You for this plugin. Works as it should.
Leer todas las 10 reseñas

Colaboradores y desarrolladores

“REST API – Filter Fields” es un software de código abierto. Las siguientes personas han colaborado con este plugin.

Colaboradores

Traduce “REST API – Filter Fields” a tu idioma.

¿Interesado en el desarrollo?

Revisa el código , echa un vistazo al repositorio SVN , o suscríbete al log de desarrollo por RSS .

Registro de cambios

1.0.8

  • Final version before being archived.
  • This update will disable the functionality in wordpress 5.0 and above and show a message in the admin dashboard.

1.0.7

  • Filter fields enabled on users Issue #9
  • Bumped wordpress version

1.0.6

1.0.5

  • Support for embedded fields (when you include the _embed GET parameter!).
  • The _links field doesn’t get stripped anymore.
  • Taking the first element of an collection with first, like _embedded.author.first.name.
  • Moved all the logic to a separate class, so it won’t intervene the WordPress core.

1.0.4

  • Updated readme.

1.0.3

  • Filter on nested fields Issue #1 implemented. Please test and leave a response here.

1.0.2

  • Added filtering for categories Issue #4
  • Tested on WordPress version 4.6.1

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