In a taxonomy template, the queried object is an instance of WP_Term, one of whose fields will be the taxonomy the term comes from.
So, you can start your taxonomy.php as follows:
$queried_object = get_queried_object () ;
$args = array (
'post_type' => 'inventory',
'tax_query' => array (
array (
'taxonomy' => $queried_object->taxonomy,
'field' => 'slug',
'terms' => $queried_object->slug,
),
),
) ;
$query = new WP_Query ($args) ;
Related Posts:
- How can I get all the posts that are related with a specific taxonomy term?
- Why is my WP_Query not working when tax_query terms are an array?
- How to add terms to my tax_query based off of the current post
- Empty tax_query array returns an empty array
- How do I search inside specific taxonomies in WordPress
- Pass array of taxonomy terms to wp_query
- WP_Query tax query part of slug
- Taxonomy Query Relation field not behaving correctly?
- Slow queries on a huge database
- How to add custom meta to ‘pre_get_terms’?
- Get posts in taxonomy randomly
- Loop posts based on permalink term
- Show multiple tax_query from 2 or more post_type in a single code
- WP Query should show No Posts when tax_query $args taxonomies don’t have associated posts
- wp_query with meta_query and tax_query
- Why pagination is not working with tax_query param?
- How to show terms from another taxonomy
- Custom taxonomy and query multi conditions
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Custom query for tag and custom tag from 2 post type
- Get the tax term in which is a post via wp_query
- Custom query for certain post type OR another post type with a certain category
- When should you use WP_Query vs query_posts() vs get_posts()?
- Nested meta_query with multiple relation keys
- order by numeric value for meta value
- Wp get all the sub pages of the parent using wp query
- Multiple relationship for multiple tax_query in WP_Query
- Return only Count from a wp_query request?
- How to query for most viewed posts and show top 5
- WordPress tax_query “and” operator not functioning as desired
- WP_Query vs get_posts
- WP_Comment_Query pagination, delving into the unknown
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- WP query taxonomy input differs to output?
- Make a WP Query search match exactly the search term
- Search custom taxonomy term by name
- WP_Query: query posts by ids from array?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Escaping WP_Query tax_query when term has special character(s)
- Sort posts by category name and title
- Does tax_query really beats meta_query in all situations?
- How to uniquely identify queries?
- What is the most efficient way of querying posts based on visits and date for current day?
- Custom WP_Query order by post_meta and (author) user_meta
- Query WooCommerce orders where meta data does not exist
- Tax_query terms ID’s using variable
- How to display post from current Taxonomy in archive page?
- WP_Query for WooCommerce Products
- pre_get_posts with get_posts
- Display posts the match taxonomy term linked from wp_list_categoies?
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- When should you use wp_reset_postdata vs wp_reset_query?
- Get posts by meta data OR title
- Identify which loop you are hooking into; primary or secondary?
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- How to make an activities stream mixing posts and comments?
- Duplicate Queries
- How to query for a week using key => value WP_Query argument notation?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to create a WP_Query to search the Title or Tag?
- Show only oldest post by author
- Order posts by tags count?
- if wp_query taxonomy term have posts
- SQL query equivalent to WP User Query
- Add and in the header while looping over custom query in page template
- How to get the posts published in last two days using WP_Query?
- Move posts to top of WP_Query if in certain Taxonomy?
- Highlighting Sub topic in a post?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Which custom query am I in and how can I access its properties & methods?
- How to count post type that has a particular term?
- Querying Multiple Custom Taxonomy Terms
- How to combine tax_query and date_query in WordPress
- Finding the next 5 posts
- how to retrieve specific product attribute value in an sql query?
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Dynamically Override Fancy Title – Part II
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Using tax_query reverses my post_type argument in a custom WP_Query
- Transient pagination not working properly
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Can not switch the queried post in pre_get_posts hook
- Find all product that contain terms with %keywords% in WP_Query
- Get term by custom term meta and taxonomy
- view queries made?
- Filter and list posts of a custom taxonomy
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- WP Query – Get WooCommerce Products with variation that is in stock
- WordPress custom archive page
- How to speed up wp_query, took more 5s to run against 100k posts
- WP_query category__in not working, only pulls from first category
- How to detect custom query inside `posts_where` hook?
- tax_query shows no results if nothing is selected
- Pass the same object to multiple widgets in a template with one query
- Is temporarily overwriting $wp_query a bad idea?