There is no build in function to achieve what you want, at least not for complicated meta queries like this. If you need to use build in functions for this, the best will be to make use of WP_Query
.
To make the query faster and to skip the unwanted returned array of WP_Post
properties, and because you are only interested in post count, you can use the following in your parameters in your arguments
'fields' => 'ids',
'no_found_rows' => true,
This might even be a bit faster than a custom SQL query, and the results from WP_Query
is cached as well.
Related Posts:
- How to make an activities stream mixing posts and comments?
- SQL query equivalent to WP User Query
- meta_query on a date range using an array of values
- How to speed up wp_query, took more 5s to run against 100k posts
- Get the Plugin Which Triggered a MySql Query in WordPress?
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Mysql query LIKE not working
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Order by custom table and multiplication
- How to correctly pass values to wpdb->prepare()?
- Why is variable not working on custom sql query using wpdb?
- Custom Query num_rows returns wrong amount
- Iterating through $wpdb query without using get_results for large query results
- Order by summing multiple values
- Query most popular terms by taxonomy over 2 week period
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- WordPress query posts with multiple post_meta data
- Update query for wp_posts and wp_postmeta
- mysql query order by
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- get_var is neither a string, integer, or array …?
- Woocommerce Get Orders By Meta Value
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- wpdb get_results() returns only 2 rows
- WP_Query always returning the last custom post
- Get a list of the last posts grouped by author and filtered by category
- meta_query dates from an array
- Different sql queries count indicator on the main page [closed]
- Parsing External Table Arguments
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to print the excuted sql right after its execution
- order by numeric value for meta value
- Wp get all the sub pages of the parent using wp query
- Pagination with custom SQL query
- Use REGEXP in WP_Query meta_query key
- How to query for most viewed posts and show top 5
- WP_Query vs get_posts
- Order by DESC, ASC in custom WP_Query
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- WP_Comment_Query pagination, delving into the unknown
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Make a WP Query search match exactly the search term
- 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
- Sort posts by category name and title
- how does $wpdb differ to WP_Query?
- 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
- find a random blogid across my multisite network that has at least one post published
- Query WooCommerce orders where meta data does not exist
- Count the number of images uploded on the website
- WP_Query for WooCommerce Products
- pre_get_posts with get_posts
- Is it true $wpdb->get_results is faster than WP_Query in most cases?
- Get posts by menu ID
- count posts from custom taxonomy terms by year
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- author.php with ACF and CPTs
- Multipart/formatted MySQL query problem
- Slow SQL_CALC_FOUND_ROWS Query
- Query Custom Meta Value with Increment
- Export wordpress table to excel
- When should you use wp_reset_postdata vs wp_reset_query?
- Get posts by meta data OR title
- Use WP_Query with a custom SQL query
- 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?
- 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]
- Show only oldest post by author
- Order posts by tags count?
- How can I connect to another WP database and use WP_Query?
- Add and in the header while looping over custom query in page template
- What’s wrong with this WP query?
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- How to get the posts published in last two days using WP_Query?
- How to count post meta key values for all posts in database
- Highlighting Sub topic in a post?
- Which custom query am I in and how can I access its properties & methods?
- How to count post type that has a particular term?
- Group posts by meta_key
- How to search for posts IN OR title OR content OR author?
- Finding the next 5 posts
- how to retrieve specific product attribute value in an sql query?
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- How to use global post counter in the loop?
- Get number of comments after modifying comment query
- How to change a custom query into a standard loop?
- Dynamically Override Fancy Title – Part II
- Would this post meta be better added to the post table rather than post_meta table
- Transient pagination not working properly
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Can not switch the queried post in pre_get_posts hook