I'm trying to return a list of posts or media via the Rest API

But it seems that when a filter incorrectly specified then a whole page of results is passed back.

So a curl command like

curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/?filter[id]=123"

returns all media items, instead of a empty list.


curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/?filter[year]=2016"

I get all media for that year.


curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/?filter[year]=2015"

returns an empty list [] , because there isn't any..fine.

So, I assume that id is not a valid filter argument, but why do I not get an error message?

The documentation for filter arg just links to wp_query method, which seems to be all about the PHP function, I admit I know very little about PHP, so I find this very confusing as to what it is saying...

1 Answer 1


WP API will ignore filter values it doesn't understand, so the following are essentially identical:

curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/?filter[id]=123"
curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/"

Any filter keys that are valid, however, will be used to filter the results, so if there are no images for the year 2015, the following will return nothing ([]).

curl -gv  "myamazingsite.co.uk/wp-json/wp/v2/media/?filter[year]=2015"

I'm not quite sure what you want your first curl command to return, if you could clarify, I'd be happy to expand this answer.

  • If I run a query and the query is wrong/incorrect, I would expect and error message. Not a pile of results. How do I know the query is wrong?
    – Mesh
    Nov 25, 2016 at 12:58
  • I realise now that that filter[id] should be filter[p], p must be a WordPress thing. ( Again as an API user how I'm I expected to know that?)
    – Mesh
    Nov 25, 2016 at 13:01
  • Well, I'm not going to argue with you on that :) The filter-functionality for WP API is mostly for advanced users familiar with WP_Query in WordPress development, so I guess the creators of WP API didn't deem in necessary to include the documentation for WP_Query in their documentation – then again, that's what this StackExchange site is for - Q&A about WordPress! Hope you got it to work :)
    – Emil
    Nov 25, 2016 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.