Making Advanced Taxonomy Queries
This article covers the topic of performing advanced taxonomy-centric queries (such as categories, tags, or custom taxonomies).
Making advanced post queries in WordPress is very well documented, but plugin and theme developers may find that they need to leverage WordPress's taxonomy system with the same level of flexibility as the post system.
Prerequisites & Assumptions
This article assumes that you are already very familiar with making MySQL queries both in and out of WordPress. You should also be very familiar with WordPress's $wpdb class object and it's various methods.
Built-in WordPress Helper Functions
This article is about making very advanced queries. Keep in mind that WordPress contains a large number of helper functions for making simple taxonomy and term queries. Please see if these functions meet your needs before continuing on with this article...
- Class: WP_Query - Detailed Overview of class WP_Query
- Object: $wpdb - Overview on the use of the $wpdb object
- Function: get_query_var()
- Function: query_posts() - Create additional custom query
- Function: get_post() - Take an ID of an item and return the records in the database for that article
- Function: get_posts() - A specialized function that returns an array of items
- Function: get_pages() - A specialized function that returns an array of pages
- Function: have posts() - a condition that determines whether the query returned an article
- Function: the_post() - Used to automatically set the loop after a query
- Function: rewind_posts() - Clears the current loop
- Function: setup_postdata() - Sets the data for a single query result within a loop
- Function: wp_reset_postdata() - Restores the previous query (usually after a loop within another loop)
- Function: wp_reset_query()
- Function: is_main_query() - Ensures that the query that is being changed is only the main query
- Action Hook: pre_get_posts - Change WordPress queries before they are executed
- Action Hook: the_post - Modify the post object after query
- Filter Hook: found_posts - Changes the value of the object found_posts WP_Query