I think you’re way overcomplicating this. Use get_terms
to get all taxonomy terms that are a child of a particular term via the child_of
argument, then use that array with a WP_Query
tax query, no custom SQL queries necessary.
Related Posts:
- Using wp_query is it possible to orderby taxonomy?
- “tax_query” parameter not working with WP_Query
- How do I exclude a custom taxonomy from the post loop
- Custom Taxonomy and Tax_Query
- Using WordPress to make a “Product Search” type navigation drilldown
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- display posts with same taxonomy term
- Including all terms in wordpress tax_query
- How to get first post in a category of a custom taxonomy
- Display one post from each term in a custom taxonomy [closed]
- Using tax_query creates a 1 = 0 or 1 = 1 in $wp_query->request
- wp_options table value
- search query within custom taxonomy term, post title and meta field
- wp query with multiple taxonomy?
- wp_query orderby title and meta key value (WP3.1)
- On Taxonomy Template page, want to add Post_Type
- Page queried instead of a custom taxonomy
- Custom WP_Query breaks default behaviour of viewing right post associated with tax-term!
- The next_posts_link() show me a aditional page in blank
- Help with a query not working with custom taxonomy
- Adding session variable and/or cookie based on user-selected input
- Excluding a custom taxonomy term breaks wp_get_post_terms
- Advanced Tax Query
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- why do drafts return as part of wp_query?
- Improving WP_Query performance for multiple taxonomies
- WP Query with custom taxonomy
- how to search in custom fields & custom taxonomy for custom search
- How to Query Database for posts with certain Taxonomy Term
- WP_Query on custom taxonomy works fine but fails if run through wp_ajax_
- Advanced Query Logic With Multiple Taxonomies
- How do I Use Multiple Loops with WP_Query?
- cannot get multiple loops using tax_query
- Display all posts for taxonomy term across multiple custom post types
- WP_Query orderby and tax_query
- Hiding taxonomies with no children WP_Query & tax_query
- Can I use OR relation for one item when calling tax_query from WP_Query and use AND for the rest?
- Set tax_query conditionally with new WP_Query
- querying posts by custom taxonomy terms right from a querystring based URL
- Query custom taxonomy by term id?
- When filtering query on custom taxonomy; main menu dissapears
- Exclude taxonomy term from all loops, but having it on widget
- Why can’t I use an array of term slugs in WP_Query?
- wp_query not resetting, last post hanging
- Using WP_Query and Query_post for the loop?
- Problem with wordpress pagination
- How to do a particular wp_query taxonomy search
- Different Taxonomy Values for Each Post
- How to get product order by two custom taxonomy in wordpress
- Wp_query…a type of term a different div
- check if a taxnomy queried in $wp_query?
- Taxonomy.php how to show post only in current taxonomy with wp_query?
- WP_Query tax_query – Show results if child has parent X
- Query custom taxonomy for category including children
- Proper way to create taxonomy queries
- how to use tax_query to apply both terms or one if one is empty
- Get current page term title to use in WP_Query
- passing moree than one value of slugs in taxonomy using variable
- Looking for suggestions on creating simple database (Help!!)
- How do you move custom fields to custom taxonomies using WP Queries
- WordPress hiding posts without content on custom taxonomy query. How to solve?
- Run next query based on first query’s term
- Get the original menu item name string instead of the label
- How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?
- Order posts with custom taxonomy array
- How to permanently delete a taxonomy
- Getting grandchildren of a post with a specified custom taxonomy?
- Taxonomy Parameters in WP Query to get posts from two different taxonomies
- Custom Taxonomy + JQuery Tabs
- Advanced AND tax_query in sidebar with 2 taxonomies
- How to query posts that are not related to any term of a taxonomy?
- Using wp_query is it possible to orderby taxonomy?
- How to limit posts to 1 from each term with tax_query?
- Loop posts without any taxonomy
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How can I get only parent terms?
- get_terms does not return any results for my custom taxonomy?
- How to display warning on post editor when trying to add new term to custom taxonomy?
- How do you remove a Category-style (hierarchical) taxonomy metabox?
- Is there a way to import terms into WordPress?
- get_terms() doesn’t return empty terms even though hide_empty is false
- Custom metabox for menu administration page?
- Remove Custom Taxonomy Base
- Exclude current post when getting related post on custom post type and taxonomy
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Populating dropdown menu with hierarchical taxonomies
- Specifying a size when displaying an image associated with a taxonomy through ACF
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- How can marge these loop code?
- Query custom post type by custom taxonomy (category slug)
- Display related products based on 2 specific product attributes values in WooCommerce
- Widget Logic use with Custom Taxonomy
- limit post by a taxonomy in the admin
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- Taxonomy archive template that shows posts from more than one taxonomy
- Drop-down filter doesn’t retrieve custom taxonomies
- Why is the category item count not updating after assigning a category?
- Add custom taxonomy for post using cron job
- How to show one post content in another post content which has same terms?
- How to update WordPress custom SQL Select query for custom taxonomies so that syntax is correct?