Now that we have covered how to perform HTTP requests and query our database using REST API, it is time to implement it. We will now be focusing on implementation of REST API and JavaScript with taxonomies in WordPress.
In WordPress, you can query for posts by taxonomy. Alternatively, you can also list terms in taxonomy for a given post.
It is fairly easy and is just a matter of few HTTP requests.
To get posts from a given category, we pass the parameter category_name
. For example, for the category sample
, we will pass the request as follows:
sample_url( 'wp/v2/posts?filter[category_name]=sample' );
Similarly, to get posts with a given tag, use the tag parameter. For example, for the tag sampletag
, we will pass the following request:
sample_url( 'wp/v2/posts?filter[tag]=sampletag' );
And if you wish to query multiple taxonomies, you can combine them in the same request:
sample_url( 'wp/v2/posts...