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
- Wp get all the sub pages of the parent using wp query
- WordPress tax_query “and” operator not functioning as desired
- Search custom taxonomy term by name
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to uniquely identify queries?
- How to display post from current Taxonomy in archive page?
- 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?
- SQL query equivalent to WP User Query
- 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
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Filtering posts by custom field value not working
- How to output different posts per page?
- How to orderby meta_value_num with dollar ($) sign
- Query: offset post list, unless it’s a specific category
- Setting get_queried_object
- Output an array of terms for a ‘tax_query’ => array()
- remove query arg from url after set query
- difference between like ‘%%%var%%’ and ‘%var%’
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Sort query by author: 1 author, then others
- Custom Query num_rows returns wrong amount
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- WP_query sorting can’t sort danish letters (æ, ø, å)
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Multisite pagination issue by multi query archive 404
- Query with relation and one without relation using multiple taxonomies?
- Automatically Query Parent Taxonomy
- Sort WordPress Posts Meta value by Week not Day
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Transient api Caches confused
- WP_Query for a taxonomy with different taxonomy types
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- Get Child Category only
- Query where ANDing slug values not working
- How to filter query loop block with a search string from the query parameters
- How to SQL query posts IDs by categories AND authors?
- Tax_Query using WP_Query not working
- Custom taxonomy in WP_Query not working
- Can’t get term id for category archive
- Query multiple post types, but different order for each
- Use get_cat_ID to retreive multiple category IDs
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- WP_Query paginate with one term per page?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- How to get_comments() ordered by date and parent?
- WP Query. Ordering posts by another post types meta
- WordPress tax_query ignoring relation OR
- Adding Category in WP_Query Not Working
- Merge two queries and remove duplicate
- Taxonomy Terms That Don’t Exist Display Results
- display all posts from category with and without terms in chronological order
- Category Archive not working for pages
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Fetch only categorized posts
- How to combine nested tax_query logic with other nested query logic?
- WP Query with sticky posts and tax_query
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Custom pagination (Title, date and teaser)
- Get a list of the last posts grouped by author and filtered by category
- Match two taxonomies to display a specific content
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?
- How to query post ids liked by the Author
- Advanced AND tax_query in sidebar with 2 taxonomies
- Modify query after meta value
- Showing posts from 4 categories along with all latest posts
- Main loop querying current template’s info only in custom category archive pages, not my posts
- tax_query not working properly with get_posts
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- Advanced Search – Is this possible?