voceconnect / thermal-api

Thermal is the WordPress plugin that gives you the power of WP_Query in a RESTful API.
http://thermal-api.com/
147 stars 16 forks source link

Get Post Types Categories #101

Closed johnsonsg closed 10 years ago

johnsonsg commented 10 years ago

I figured out how to get all posts from a Post Type, but how do I get all from a category in a Post type. I want to be able to pull from particular categories. This is what I have so far:

http://www.sgo-beta.com/wp_api/v1/posts?per_page=500&post_type=listing

But I need to be able to get from each category if needed by category only.

banderon commented 10 years ago

The same way that you're specifying the per_page and post_type, you can pass parameters to limit the categories of returned posts. Look through the "Taxonomy Filters" under "Posts" in the documentation: https://github.com/voceconnect/thermal-api#posts

If you need to get the taxonomies that the post type supports, take a look at the taxonomy calls: https://github.com/voceconnect/thermal-api#taxonomies

johnsonsg commented 10 years ago

I tried that and I get this: {"posts":[]}

http://www.sgo-beta.com/wp_api/v1/posts?per_page=500&post_type=listing&category_name=Virginia

johnsonsg commented 10 years ago

Tried it this way to:

http://www.sgo-beta.com/wp_api/v1/posts?per_page=500&post_type=listing&taxonomies=virginia

kevinlangleyjr commented 10 years ago

As @banderon said above, you should reference the Taxonomy Filters under the posts parameters - specifically here https://github.com/voceconnect/thermal-api#parameters.

To use the category_name parameter, you'll have to use the slug not the name.

For the taxonomy parameter, it accepts an associative array where the key is the name of the taxonomy and the value is an array of term IDs. Post that exist in any of the terms will be included in the results.