Wp_Query
should be able to do this for you. Pass it the appropriate parameters, including a tax_query
, and check found_posts
.
$p = new WP_Query(
array(
'post_type' => 'custcpt', // your CPT
'tax_query' => array(
array(
'taxonomy' => 'custtax', // your tax
'field' => 'id',
'terms' => $cat->term_id, // your term ID
)
),
'ignore_stickie_posts' => true,
'fields' => 'ids',
)
);
echo $p->found_posts;
Untested, but should be close.
Related Posts:
- Get posts under a category with SQL
- Bulk Change WordPress category Slug
- Is There a Difference Between Taxonomies and Categories?
- Check if a post is in any child category of a parent category
- How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
- get_terms vs. get_categories: does it matter?
- Woocommerce get category image full size
- Order get_terms() By Custom Field
- Control term order on a per-post basis
- Fixing category count
- How can I get category ID by category name?
- get_terms name__like list categories according to letter
- Elegant way to add parent categories?
- How can I select a primary category?
- Programmatically create product category and add thumbnail in woocommerce
- How to order the get_categories result
- Send an email when custom post type category is changed
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Excluding posts from a category but only if they’re not in multiple categories
- Update term count using a callback function
- Get terms that are associated with products from current category
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Getting the sub category
- Use get_term_children to get the sub category of a parent category for the current post
- Deleting All tags except categories Wp database
- Action hooks returning old category instead of new category
- Update wordpress post terms programatically
- Display empty taxonomy terms with get_terms()
- Get a list of Terms for a specific category
- When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?
- List Terms in Category
- How do I get a list of all categories that a given user has written blog posts for?
- Set post categories to include parents when setting child category
- How to get data about category in category.php
- Limit number of terms that a custom taxonomy can save per custom post type
- Modify WordPress SQL Query to pull from within a category
- How can i insert term in a specific language of Polylang?
- batch adding posts to a category based on matching regex for title with SQL
- SQL to migrate post types to taxonomy
- Display Posts Loop for each parent and for each Child
- Is There a Difference Between Taxonomies and Categories?
- Get posts from specific taxonomy term
- Custom SQL Query: Get all posts with category id and a concated list of tags on each post
- Getting category URL with hyphens, not spaces
- get_terms function not returning anything
- Display custom taxonomy attached to the post on post single page
- wp_dropdown_categories not showing option as selected
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- SQL query to return categories and category parents
- Get Categories Where Taxonomy Equals ‘n’
- Overriding default calendar to show posts from a category
- Display sibling categories on category page
- Count tags for a specific category
- How to Link to Most Recent Custom Post of Same Term
- set terms to category and subcategory
- Getting Category Children
- Showing HTML if Post is In Certain Taxonomy Term
- Exclude categories by ID
- How to store category and tags separatly on wordpress?
- SQL query to get posts from multiple categories but not in a category
- Post to inherit custom category background image from parent
- wp_delete_term or wp_delete_category?
- Update custom category fields front-end
- Combining these queries? (Same taxonomy term + same category as post)
- Add properties to term object
- get_object_term_cache duplicate terms after update to wordpress 6
- List taxonomy terms assigned to a post in hierarchical view
- Sort categories by custom field in WordPress admin
- How to get immediate children of a ‘term’ parent id through ‘get_terms’?
- Ordering terms whilst in loop
- Replace deprecated get_category_children code with get_terms
- Can’t display posts by filtering categories using isotope.js
- Get WooCommerce product category list in functions.php
- Restrict retrieved terms by category?
- List non-empty categories from a custom post type
- Get category from slug list
- Add subcategories posts to the counts column at the admin’s categories list
- show only terms from parent category
- Categories and Tags Conflict after Woocommerce Installation
- Get category of a taxonomy for a queries object in a loop
- get_terms sort order with child categories of varying depth
- Getting a sub category based on a category name
- Getting Post Tags From Certain Categories
- Display List of Categories Within a Custom Taxonomy
- Help with SQL query, how to add taxonomie terms with value stored in options?
- List Terms by category
- get_adjacent_post_link excluded_terms ignored
- How to add a new child category via an SQL statement?
- Why is my post categories not displaying?
- exclude parents from the_terms
- Problem importing categories and sub-categories
- finding out the top 5 source ( source is a custom taxonomy ), in a given category
- Modify functions.php to add a term ‘uses-theme’ set to theme name on post save
- Use get variable when rewritten url in wordpress
- Issue on Listing Sub Product Categories In Woocommerce
- Taxonomy term RestApi data 10 rows limitions
- List the category tree of all the product_cat categories
- hide_empty property not working when using get_terms