Documentation / Tutorials / Tutorials & How to’s
How to retrieve post from specific category using taxonomy
/ Tutorials & How to’s / How to retrieve post from specific category using taxonomy
Task: Listing post from custom post type(CPT) where category is "category1" and Type is "type1".
CPT Example :
Custom Post type: as_docs
Category Slug: as_category
Taxonomy Slug: as_type
How it works:
The query and result is broken in 4 parts.
start:
tax_query:
meta_query:
date_query:
run:
Below Code gets post from cpt as_docs
<!--- Get Post from CPT --> [aw2.query posts_builder part=start] { "posts_per_page": [aw2.get module.count /], "post_type": "as_docs", "post_status": "publish", "order": "[aw2.get module.order default='ASC' /]", "orderby":"[aw2.get module.orderby default='date' /]" } [/aw2.query] <!--- Get Post from CPT End -->
Below Code gets post from cpt as_docs from category "as_category" where "as_category" is slug for Category
<!--- Get Post from Category --> [aw2.query posts_builder part=tax_query] { "taxonomy": "as_category", "field": "slug", "terms": "category1" } [/aw2.query] <!--- Get Post from Category End -->
Below Code gets post from cpt "as_docs" from category "as_category" where "as_category" is slug for Category & from Taxonomy Type "as_type"
<!--- Get Post from Type--> [aw2.query posts_builder part=tax_query] { "taxonomy": "as_type", "field": "slug", "terms": "type1" } [/aw2.query] <!--- Get Post from Type End -->
The above code generates the WP_query using the json