Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Count of posts by different parameters?

Use WP_Query with a tax_query and a meta_query argument, and return only IDs to save a bit of server resource.

$args = array(
  'post_type' => 'post',
  'tax_query' => array(
    array(
      'taxonomy' => 'people',
      'field'    => 'slug',
      'terms'    => 'bob',
    ),
  ),
  'meta_query' => array(
    array(
      'key'     => 'age',
      'value'   => array( 3, 4 ),
      'compare' => 'IN',
    ),
  ),
  'fields' => 'ids'.
);
$query = new WP_Query( $args );

And check the found_posts element of $query— var_dump($query->found_posts);

Related Posts:

  1. WordPress database error: [Not unique table/alias: ‘wp_postmeta’]
  2. How much faster is a tax query than a meta query?
  3. Use custom posts as taxonomy term meta replacement?
  4. Is it possible to sort the post based on a custom field?
  5. List Custom Taxonomy Values according to a Post Meta Value
  6. get_the_terms() to show all custom taxonomies
  7. Single reusable value for post meta: Custom Taxonomy or Post Meta?
  8. What is faster: custom taxonomy or serialized post-meta for db retrieval? (over 60,000 posts)
  9. Is it possible to store Json data in post_meta and manipulate
  10. Add Custom Taxonomy for Blog Meta Info
  11. How to separate posts in loop?
  12. Creating terms vs custom post meta to save data?
  13. Does using custom taxonomy is more CPU efficient than using meta_data?
  14. wp_query not resetting, last post hanging
  15. WooCommerce custom taxonomy as meta?
  16. Sort taxonomy page alphabetically by meta rather than default post date
  17. Convert post meta to custom taxonomy?
  18. Count tags for current post and save into custom meta field (and update it on post edit)
  19. Is it possible to sort the post based on a custom field?
  20. Custom post type term names with ampersand in the term name
  21. Looking for suggestions on creating simple database (Help!!)
  22. get meta fields and taxonomy of any post type
  23. Where to put a migration script to switch post information?
  24. Update fields with post object and custom tax with wp_insert_post
  25. How can I show custom field according to taxonomy?
  26. Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
  27. How to handle custom taxonomy archive when no posts will have that taxonomy
  28. How can I list all the meta in a custom taxonomy?
  29. Using wp_query is it possible to orderby taxonomy?
  30. Advanced search form with filters for custom taxonomies and custom fields
  31. “tax_query” parameter not working with WP_Query
  32. How do I exclude a custom taxonomy from the post loop
  33. get_posts assigned to a specific custom taxonomy term, and not the term’s children
  34. How can I get only parent terms?
  35. How to modify a taxonomy that’s already registered
  36. Retrieve posts by term id custom query
  37. Change order of Custom Taxonomy List
  38. Get the the top-level parent of a custom taxonomy term
  39. get_the_term_list without links in 3.1
  40. Inserting terms in an Hierarchical Taxonomy
  41. get_terms – only top level
  42. Custom taxonomy terms not showing as list Gutenberg Editor
  43. Altering the appearance of custom taxonomy inputs
  44. How to only list the child terms of a taxonomy and not their parents?
  45. Get term SLUG by term ID
  46. Is ACF being a honey trap? [closed]
  47. Get term name from term ID?
  48. Check if Current Category has Children
  49. How to use taxonomies on attachments with the new Media Library?
  50. Hierarchical taxonomy UI
  51. WordPress taxonomy radio buttons
  52. How to prevent new terms being added to a custom taxonomy?
  53. Custom taxonomy, get_the_terms, listing in order of parent > child
  54. How to remove the tag cloud from custom taxonomy admin page?
  55. custom taxonomy and pages rewrite slug conflict gives 404
  56. Inserting a term into a custom taxonomy
  57. Count posts in custom taxonomy
  58. How to add images to taxonomies?
  59. Read-only taxonomy (user can assign term but can’t create or edit existing terms)
  60. Remove taxonomy base or term from url
  61. Can you add the visual editor to the description field for custom taxonomies?
  62. Adding Category/Tag/Taxonomy Support to Images/Media
  63. Add default WordPress tag meta box to User Profile
  64. Custom Taxonomy Endpoint Pagination using paginate_links()
  65. How do I get the top-level terms in a custom taxonomy?
  66. Check if a post has any term in this custom taxonomy?
  67. Query Custom Post by Taxonomy Category
  68. Custom columns on edit-tags.php main page
  69. Loop through custom taxonomies and display posts
  70. How do I add a custom taxonomy as an option for menus under “Appearance” > “Menus”
  71. custom post type taxonomy “tag” archive : no post found
  72. How to get WooCommerce Product Category Link by ID?
  73. Order get_terms using a Custom Field
  74. Add custom taxonomy fields when creating a new taxonomy
  75. get_term_children for immediate children only (not grandchildren)
  76. Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
  77. Custom taxonomies capabilities
  78. Contact Form 7 – Populate Select List With Taxonomy [closed]
  79. Can’t get a custom template taxonomy page to display
  80. Query users by custom taxonomy and user role
  81. Display category posts grouped by taxonomy
  82. WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
  83. Custom Taxonomy and Tax_Query
  84. Custom Taxonomy Archive Page
  85. How to display custom taxonomies in posts?
  86. Get taxonomy names by post id
  87. Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
  88. How to assign multiple roles for capabilities array withini register_taxonomy function?
  89. Filtering custom taxonomies
  90. Can custom taxonomies be displayed inside of a custom meta box?
  91. Determine Term depth
  92. Exclude Specific Term from Search
  93. How to get current term in my custom taxonomy in WordPress?
  94. Is there a way to ‘Lock’ a Taxonomy?
  95. Bulk term assignment for attachment taxonomies
  96. Creating Custom Taxonomy without mapping to any post type
  97. Using WordPress to make a “Product Search” type navigation drilldown
  98. Hide the term description on the term edit page, for a given taxonomy
  99. Why is my working Custom Taxonomy not in get_taxonomies array?
  100. Add post classes for custom taxonomies to custom post type?
Categories custom-taxonomy Tags custom-taxonomy, post-meta
Permalinks not working in WordPress
White blank page when Updating/Draft/Publishing Page/Post

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress