This should do the trick.
<?php
// start with an empty array
$all_term = array();
if ( have_posts() ) {
// loop through all posts, this could go outside of the main loop or be part of it, if placing outside the main loop be sure to reset the loop or namespace your queries
while ( have_posts() ) {
the_post();
// add the list of terms for a given taxonomy to the $all_term array
array_push($all_term, wp_get_post_terms($post->ID, 'my_taxonomy', array("fields" => "ids")));
} // end while
} // end if
// remove duplicates from the $all_term array
$all_term = array_unique($all_term, SORT_REGULAR);
// output the result
echo count($all_term);
?>
Related Posts:
- How to update incorrect post count in taxonomy?
- Check if an array of posts has posts from a specific category
- How to trace/fix false $term->count, rogue term relationships?
- How to get terms of not only the current cat but also of all its children
- What is ‘term_group’ for ‘order_by’ in get_terms()?
- Order get_terms by term meta
- Get parent id by term id
- When to / not to use wp_get_post_terms vs get_the_terms?
- Why does WordPress combine a term with the same name in the wp_terms table?
- Child terms from multiple parents?
- Exclude Child Terms From Parent Posts
- same taxonomy for several post types: how to hide empty in a specific post type?
- How to sort terms with diacritical signs?
- get_terms(); show private posts when logged in
- Get category ID after wp_insert_term
- Count posts that have specific taxonomy term attached
- How do I access a single term from a post?
- How to order get_term_children output by alphabetic order
- get_post_terms not working as expected
- wp_update_term not creating new unique slug
- has_term() does not return when term is assigned post?
- get_terms() but with additional dimensions?
- Wp set post terms not work
- get_terms only show term if there is a post using it
- Get the Term List – Ordering
- Reduce / optimize calling of wp_get_object_terms() when generating permalinks
- How to order and count get_terms by specific post type?
- Get those terms with a specific meta key value
- get_term_by “name” not working with & in name
- I want to loop through Woocommerce Product Catogories and show them in dropdown
- setting taxonomy term to bulk posts using ids
- Do I have to set parent when set post term?
- Display custom taxonomy on single post
- Does get_terms() use any sort of caching on its query?
- Get random out from get_terms()
- Post count by month of taxonmy term
- Get count of terms with a post and another taxonomy term?
- Categories order with get_terms_args not working in 4.7
- Faceted search with WP-API data
- Show List of Terms (not posts) that have been Recently Updated?
- import_id parameter for wp_insert_term to create custom ID for category
- Query to get term id using post id?
- How to get a post’s associated taxonomies and terms in wp api v2
- Get all terms linked to a post and include those who not connected from get_terms and sort
- Add HTML to Term Description
- Get the ID of category page with or without any posts
- single_term_title() running before get_the_title() [closed]
- Get terms within a custom taxonomy
- How do I print a term list but alter the link text?
- How to get the $meta_type given the $object_id
- $args for get_terms() to return ORDER BY FIELDS
- How to create a array that contains all of the children slugs of a specific parent category
- Getting terms to have space between them
- Temporarily un-associate term for an amount of time
- Custom term templates
- INSERTING Data into table with placeholders
- Get Custom Post Child Term
- Order terms by count – missing terms
- Get fuzzy matches from get_term_by
- Taxonomy Drop Down with hierarchical view using $terms
- How to check if a term is parent to another?
- Create Terms on taxonomy by text field
- Customizing the wordpress tag-cloud output
- How to use category slug to echo a page’s content with the same slug
- Can we apply hide empty to get_the_terms?
- get_terms() delivers wrong count with custom taxonomy childs on custom post type
- Why does term get inserted twice when using dynamic slug?
- How to use get_terms() returning only the terms that have posts with a certain custom field value
- get_queried_object not work in taxonomy page
- Count tags for current post and save into custom meta field (and update it on post edit)
- how to show all categories by get_terms
- wp_set_object_terms() to update a post taxonomy value
- Order get_terms by multiple values
- Get All Taxonomy Terms From Get_terms Array With Specific Array Key
- Confused by get_the_terms to use in a new wp_query
- get_terms for all custom taxonomies shows invalid taxonomy error
- Add subcategories posts to the counts column at the admin’s categories list
- Change the last separator in the_terms
- How to show only tagged CPT categories / taxonomies for a custom post type?
- Is there any WordPress way to get all categories for some selected posts?
- Order terms by creation date
- Unable to retrieve any child terms using get_terms
- Importing custom DB table entries as posts with Categories
- Get count for all terms inside a parent term
- add links to list of post terms
- list of tags overlay
- When I Use function wp_insert_term() function it gives me Invalid taxonomy object
- Trying to Display Number of Posts in Term
- Getting Term_id – Taxonomy Metadata plugin
- store an array of all the terms existing
- Get only last child category link of products
- Get Parent Custom Taxonomy Term and Color Div background
- How to get the count for each taxonomy term
- get_the_term_list() display in ul li and remove tag
- How to add a post counter to the list of custom taxonomy terms?
- Custom field drop down to set the term of the post when published
- Attempting to filter posts using get_terms
- How we retrieve the ‘tags’ and ‘attachment’ of the custom post which is created by wp_insert_post();
- How to solve/debug get_terms suddenly showing no results?
- How can I replace the values in WP_Term?