0

so I am looking into the wordpress REST API for the first time.

I have some questions that may sound ridiculous to those that are familiar with it, but i am confused as to how it works.

So natively wordpress works by its page query ( wp_query ) to retrieve posts associated with that particular archive.

If i was to use the REST API to query posts, on the a particular archive page, does it query all posts in the database, or does it be specific to that page's inbuilt query? By the structure of the API queries, it looks to be just a general search for posts, unless you specify the taxonomy.

another question, which may sound complex, is there a feature within the API where a person can find taxonomy terms associated with posts for a particular archive page?

in what instances ( other than creating a headless site ) would a developer choose to use the API to build queries, rather than using wp_query. Is there performance benefits to using the API over the native methods of retrieving information?

i would be grateful for any insight into this.

1 Answer 1

2

If i was to use the REST API to query posts, on the a particular archive page, does it query all posts in the database, or does it be specific to that page's inbuilt query?

The REST API is for getting raw data for external applications or via AJAX with JavaScript. It's not intended to be used for building archive pages or anything like that. The API only returns data according to the parameters you set; it doesn't know anything about a page's existing query.

another question, which may sound complex, is there a feature within the API where a person can find taxonomy terms associated with posts for a particular archive page?

No.

You can get a list of posts in a particular taxonomy term by specifying that term in the API request, so if the archive page was for a particular term you could get posts for that term using the API, but that's all.

If you want to, for example, get all tags used by all posts on the current category archive, then the REST API isn't going to help with that.


Based on your questions I'm inferring that you want to implement some kind of faceted search or filtering. The built in REST API endpoints do not have any built-in behaviour to help with this.

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.