• Resolved sa_ostad

    (@sa_ostad)


    What is the best way to get list/information of media/images in specific category with category name in WordPress Rest-API?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter sa_ostad

    (@sa_ostad)

    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 .

    Plugin Author webbistro

    (@webbistro)

    Hi @sa_ostad,

    Try this:

    
    {{base_url}}/wp-json/wp/v2/media?filter[media_category]=cat_name
    

    Best,
    -Nadia

    • This reply was modified 7 years, 8 months ago by webbistro.
    • This reply was modified 7 years, 8 months ago by webbistro.
    Thread Starter sa_ostad

    (@sa_ostad)

    I test it, but it just return all the medias!

    
    {{base_url}}/wp-json/wp/v2/media?filter[media_category]=LeftSlideshow
    
    Plugin Author webbistro

    (@webbistro)

    Hi @sa_ostad,

    Actually cat_name means cat_slug, can you please try to use a lowercased version?

    Best,
    -Nadia

    Plugin Author webbistro

    (@webbistro)

    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

    Thread Starter sa_ostad

    (@sa_ostad)

    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
    
    Plugin Author webbistro

    (@webbistro)

    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 7 years, 7 months ago by K. Adam White. Reason: removed potentially confusing brackets
    Thread Starter sa_ostad

    (@sa_ostad)

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Get list of Media from specific category in Rest-Api’ is closed to new replies.