I can use this:
{{base_url}}/wp-json/wp/v2/media?media_category=4
for get the medias in category id 4
but I need to get it base on Media_category name .
Hi @sa_ostad,
Try this:
{{base_url}}/wp-json/wp/v2/media?filter[media_category]=cat_name
Best,
-Nadia
-
This reply was modified 8 years, 9 months ago by
webbistro.
-
This reply was modified 8 years, 9 months ago by
webbistro.
I test it, but it just return all the medias!
{{base_url}}/wp-json/wp/v2/media?filter[media_category]=LeftSlideshow
Hi @sa_ostad,
Actually cat_name means cat_slug, can you please try to use a lowercased version?
Best,
-Nadia
Another thing, have you set “Show in REST” option for media_category? You can find it on Settings > Media > Media Taxonomies (tab), click “Edit” button next to the taxonomy name.
Best,
-Nadia
I did this but:
Another thing, have you set “Show in REST” option for media_category? You can find it on Settings > Media > Media Taxonomies (tab), click “Edit” button next to the taxonomy name.
for both lowercase and exactly name It just show me list of all medias!
{{base_url}}/wp-json/wp/v2/media?filter[media_category]=leftslideshow
Hi @sa_ostad,
Actually, the question is not about Enhanced Media Library and, unfortunately, I am not a REST API expert. I googled the issue and found this: https://wordpress.stackexchange.com/questions/248182/wp-rest-api-no-longer-supports-filter-param-so-how-do-i-get-posts-in-a-custom-t, but this does not work for me either.
The only way I made it work is:
{{base_url}}/wp-json/wp/v2/media?media_category[]=3
where 3 is the ID of the term.
Best,
-Nadia
filter is not supported by the core REST API; it can be added in by using the https://github.com/wp-api/rest-filter plugin, but we encourage querying by ID over slug (as slugs can change unexpectedly in some situations). The approach I use to query by term slug is roughly this:
– Query the media category terms collection endpoint with ?slug=mediacategoryslug and make a note of the matched item’s ID
– Query the media endpoint with ?media_category[]=XX, where XX is the ID of the matched post from the first request
While this is two requests, not one, you can store the ID of the term locally in your app so that you don’t need to re-request it later to make subsequent calls.
-
This reply was modified 8 years, 9 months ago by
K. Adam White. Reason: removed potentially confusing brackets