Terms generally should have a count
parameter that you can use. I’m not sure if this is accurate across multiple post types though.
This may not be the fastest solution but one option could be the additional parameters for WP_Query to both reduce the number of queries and the returned values. 10up has a good article on this in regards to WP_Query Performance. An example query could look like this:
$the_query = new WP_Query( array(
'post_type' => 'post',
'no_found_rows' => true,
'tax_query' => array( array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $term->term_id
) ),
'no_found_rows' => true, // Don't calculate pagination
'fields' => 'ids',
) );
You could cache the results until the next time terms are added too using the added_term_relationship
hook which you could take advantage of to speed up future requests.
Related Posts:
- Is it a good idea to improve meta query performance by adding tax query?
- Nested meta_query with multiple relation keys
- Multiple relationship for multiple tax_query in WP_Query
- Return only Count from a wp_query request?
- WordPress tax_query “and” operator not functioning as desired
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- Differences Between WP_Query() and get_posts() for Querying Posts?
- Escaping WP_Query tax_query when term has special character(s)
- Does tax_query really beats meta_query in all situations?
- Should I use Transients with W3 Total Cache APC Caching? [closed]
- What is the most efficient way of querying posts based on visits and date for current day?
- Tax_query terms ID’s using variable
- Count the number of images uploded on the website
- Is it true $wpdb->get_results is faster than WP_Query in most cases?
- count posts from custom taxonomy terms by year
- Slow SQL_CALC_FOUND_ROWS Query
- Why is my WP_Query not working when tax_query terms are an array?
- get_the_title($postID) OR get_the_title()?
- if wp_query taxonomy term have posts
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to combine tax_query and date_query in WordPress
- How to use global post counter in the loop?
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- 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
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- Find all product that contain terms with %keywords% in WP_Query
- Slow speed and high CPU usage for my code. How to improve it?
- Multiple queries on Home Page – page load/site speed issue
- Get term by custom term meta and taxonomy
- WP_Query Performance Issues with meta_query
- tax_query shows no results if nothing is selected
- WP_Tax_Query with post_tag not working
- get complex results set according to category structure
- WP_Query tax_query problem
- How to add terms to my tax_query based off of the current post
- Count total number of post in foreach loop
- Too many posts cause slow load when paginating
- Query all posts in a given taxonomy
- Change default ordering of taxonomy terms – pre_get_terms
- tax_query OR with empty result returns all posts
- WP_Query, tax_query and term_meta: How to?
- Is it possible to dynamically get queried term AND taxonomy?
- Empty tax_query array returns an empty array
- How can i simulate “taxonomy__in” in query?
- WP_Query times out
- Get list of terms that have posts in another term
- Improve wp query perfomance on large db
- pre_get_posts Remove tax_query Completely
- tax_query: Order by slug?
- reducing the amount of wp_query calls
- Meta Query relation “AND” not working
- Tax query clause inside a meta query clause?
- Nested tax_query that allows specified categories OR tags, but NOT other categories
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Populate tax_query terms parameter with post term
- Getting the current post number / make posts increment
- Use more than one query, but prevent duplicates – at scale!
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Fetch posts that match term slug first two letters (wp query)
- WP_Query | Tax_Query Relation | Unable to use ‘OR’ as it then allows all products, help me finish my query?
- WP_Query tax query part of slug
- Slow page loads due to WordPress Core Query
- Taxonomy Query Relation field not behaving correctly?
- Display tags with random thumbnail from selection of posts with that tag
- Tax query AND/OR meta query [duplicate]
- Should wp_query automatic meta and term cache priming be used in an enviroment with an object caching
- Loop Performance > JSON files vs. WP_Query vs. REST API
- How to increase load time of an archive/search page (WP_Query)
- use of 10 new WP_Query : loading too slow (with url) [closed]
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- How to count posts with specific arguments
- Query with meta_query and tax_query together not working properly
- Adding a tax_query to a WP_Query Object
- Finding WordPress Posts assigned to multiple categories
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- What is the best way (regarding performance) to set transients for logged in users?
- Tax Query only returns for the first of several terms
- exclude product with available tag
- How to add tax_query to $args with concatenation
- How to print term name inside wp post loop
- Get posts in taxonomy randomly
- Loop posts based on permalink term
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Is it possible to add relation between meta_query and tax_query?
- How to restrict search on a certain page to only return results against custom taxonomies?
- Function using get_posts() with tax_query not working when called from functions.php
- 2 queries with counters
- How to avoid filling up an array each time I run a WP_query?
- Tax_Query using WP_Query not working
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Which is from this queries is more faster
- Show multiple tax_query from 2 or more post_type in a single code
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- Having a variable based on $post_count increase when i move to the next page of results
- Any quicker alternative for WP_Query “NOT IN”
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- Facing problem with tax_query results