I found a custom solution, this is the function :
function get_all_categories_linked_to_post_type( $post_type ) {
$a_terms = array();
$the_query = get_posts_by_type($post_type);
if( !empty( $the_query->posts ) ) {
foreach ($the_query->posts as $post) {
$terms = wp_get_post_terms($post->ID, 'category');
if( !empty( $terms ) ){
foreach ( $terms as $term ){
if (!array_key_exists( $term->term_id, $a_terms)) {
$a_terms[ $term->term_id ] = $term;
}
}
}
}
}
return $a_terms;
}
Related Posts:
- Get the first post term
- Add Category Taxonomy Support to Custom Post Type
- Exclude a category from WP_Query
- Custom Post Types on Category Pages
- Adding Categories to a WordPress Custom Post Type?
- How to display regular posts & custom post types that fall under a category using just the generic category template?
- WP_Query ignores post_type in category view
- How to filter custom post types by custom category taxonomy
- How to list all categories and tags in a page?
- Pagination not working with custom category template
- remove support for ‘Categories’ for a custom post type
- Remove date and category filters when editing custom post types
- How can you make permalink work for custom post type and taxonomy?
- Filter get_categories() for taxonomy term in WordPress
- Anyway to assign custom post types to a specific category?
- List with categories, subcategories and posts of custom posttype
- wp_list_categories and custom post types
- Automatic category for a Custom Post Type
- How can i list custom post type categories?
- Query Custom Post by Category
- How to display the categories of the post? (custom post type)
- Display Custom Category (taxonomy) Name in Custom Post Type
- Show Post Count of a Category
- CPT posts listed by category with custom rewrite URL, please help!
- Multiple custom post type loops in category.php
- Add category in post type dynamically
- Filter categories of posts with checkboxes
- Use post as category
- How to get the post type from a category id?
- Insert HTML inside link in a walker
- Use regular category with custom post types
- Set menu active state for custom posttype and category, given custom taxonomy term
- Display all posts in main category and 1 subcategory
- Getting posts under the custom post type ui category
- Separate custom categories from default category
- How to display custom taxonomies with links in filter menu?
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Add custom post type settings to wordress default posts
- Hide parent categories when clicked, and show it’s childs
- How to display “Category and Post_tag” component in a CPT Gutenberg edit screen?
- Remove CPT name from permalink but add %category% instead
- Set a checkmark in a category based on a URL-parameter
- Custom Post Type and Category Base Rewrite Issue
- I am having Trouble to get list of Categories of Custom post Type
- Custom post type and category link together
- Categories filtering in new post
- WP the_posts() on single-cars.php get category link
- Why does accessing url by category cause issues with post types?
- How can I have different content for different countries?
- Why does my taxonomy have a category style div id?
- Invalid Taxonomy
- Displaying Custom Posts
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Include custom post type custom taxonomies in Categories widget
- custom query with custom post type and category slug
- WordPress custom post categories and subcategories on category.php
- Use post in multiple places on a page with multiple posts
- Custom Post Type Custom Archive Page Not Working
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Archive Template being used instead of Category Template for Custom Post Type
- Custom post type specific category box
- Custom Taxonomy Taxonomies of Same Name point to first created URL
- category.php not showing custom post types
- Post category behave like a Post in back office menu
- Save data is post using php front end
- Modify category permalink to use post type slug
- How to output custom post type title on custom page with category next to it?
- Cannot use object of type WP_Error as array display category
- Create custom post type categories
- Cannot get to work tax_query array for terms
- Set a Default CPT taxonomy by taxonomy id
- Automatic Set Category For A Custom Post Type
- how to create custom taxonomy drop downs for parents and child
- Only show categories that have posts within custom post type
- Query the title of the page to show posts with matching category in the loop
- How to create groups like that in buddypress?
- How to Show all Values in category.php page using post_type
- Getting list of Categories for Custom Post Types
- can’t see categories in appearance-menu-categories
- Custom post type URL – filter by taxonomy
- Custom Post Type + Category archive
- How to query all custom posts of a certain type and checking what category they have
- Exclude categories For Custom post types
- Post Editor: display categories from current post type taxonomy only?
- Show custom post type in archive page by category
- I have a custom post type that I want to query a dynamic category name from a custom meta field
- Display all post types together
- Trying to create hierarchy between 3-4 custom post types
- Having some trouble properly displaying Custom Post Types in templates
- Displaying wp post categories into my custom metabox
- WordPress custom post type post and category links 404
- Custom post type and category permalinks
- Bulk edit for custom taxonomy
- show only one category posts in admin
- One set of categories for multiple custom posts
- Choose custom post type template by category
- Are custom posts included when getting a categories’ posts?
- How can I show second most recent post in sidebar, if most recent post is open in the browser?
- Custom Post Types Permalink
- How to add categories to a custom post type using wp_insert_post($new_post);