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
- Use REGEXP in WP_Query meta_query key
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- find a random blogid across my multisite network that has at least one post published
- Get posts by meta data OR title
- WP_Query ordered by custom field that is a date string?
- Duplicate Queries
- What’s wrong with this WP query?
- How to count post type that has a particular term?
- Group posts by meta_key
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Order By Multiple Meta Fields
- WP_Query Performance Issues with meta_query
- Should close $wpdb via $wpdb->close()
- Query Set Order By Author
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- How do I search inside specific taxonomies in WordPress
- How to orderby meta_value_num with dollar ($) sign
- Query: offset post list, unless it’s a specific category
- Single meta_query query using OR instead of AND in request’s WHERE statement
- What’s the purpose / logic of split_the_query in WP_Query->get_posts
- remove query arg from url after set query
- difference between like ‘%%%var%%’ and ‘%var%’
- Slow WP_Query for custom post type
- Hide Administrators From User List except current user (administrator)
- Advanced SELECT query with condtional statements
- Using hook to use DISTINCT in a wp_query
- Overwrite YoastSEO meta-tags with another page’s [closed]
- pagination with ‘no_found_rows’ => true,
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Query with relation and one without relation using multiple taxonomies?
- Wp query show post by author name or post title or post content
- 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?
- Why Query is returning empty array?
- meta_value timestamp older than now
- Placing a widget with $wpdb query
- Get posts from category with custom query
- Query where ANDing slug values not working
- How to filter query loop block with a search string from the query parameters
- WordPress Insert not working with ajax
- 2 queries with counters
- How to SQL query posts IDs by categories AND authors?
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- how to translate countries output from wp database?
- Query multiple post types, but different order for each
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Passing in MySQL prepare statement parameter separately throwing error
- Delete oldest wordpress post (SQL query)
- order posts by a secondary query that counts items
- INNER JOIN custom tables – SQL Query
- use mysql variable in a $wpdb->query to reindex a column?
- Fix wp_term_relationships slow query in get_posts
- How to get_comments() ordered by date and parent?
- Query postmeta based on meta_value, return array of post_id
- Adding Category in WP_Query Not Working
- Merge two queries and remove duplicate
- What argument does my function need to echo get_results() query results
- Fetch only categorized posts
- Custom pagination (Title, date and teaser)
- Display Count of posts
- Fire query on ajax post url page
- How to query post ids liked by the Author
- Showing posts from 4 categories along with all latest posts
- SQL query into to WP query
- Use meta query only 3 or more results?
- Search results stuck on page 1
- Use value from meta key array for use in WP_Query