wp query – How to iterate _fields parameter in custom REST api endpoint

I am trying to fetch additional fields in wp/v2 namespace using post endpoint. How do I replicate the _fields property to get wp:conditions for access to the featured image and what not and all the stuff that doesn’t come with get_posts / WP_Query right away? Here is my sample logic for the data I want:

`https://example.com/wp-json/example/v1/posts_by_category?_fields=author,id,excerpt,slug,title,link,_links,_embedded&_embed&_embedded.wp:term[0].slug=${params.slug}`

I’m not sure how to add this functionality to my custom function.

Leave a Comment