Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 270 characters in body
Source Link
Djave
  • 258
  • 4
  • 25

I have a Custom Post Type that uses the default category, the same as the posts, and some other post types in my site. How can I list all non-empty categories from the custom post type?

For instance, if I have categories “Cat 1”, “Cat 2" and “Cat 3” and I have a default post with a category of “Cat 1", and a custom post with categories “Cat 2” and “Cat 3". How would I write a function that would return “Cat 2” and “Cat 3"?

It seems like the get_terms() functions don’t support a post_type argument. Is there a way I can add some other query to a get_terms() function?

I know that it is possible to hide unused terms:

$terms = get_terms( array(
    'taxonomy' => 'category',
    'hide_empty' => true, <-----
) );

However this hides empty for all post types, I'd like to hide empty for just a custom post type.

I have a Custom Post Type that uses the default category, the same as the posts, and some other post types in my site. How can I list all non-empty categories from the custom post type?

For instance, if I have categories “Cat 1”, “Cat 2" and “Cat 3” and I have a default post with a category of “Cat 1", and a custom post with categories “Cat 2” and “Cat 3". How would I write a function that would return “Cat 2” and “Cat 3"?

It seems like the get_terms() functions don’t support a post_type argument. Is there a way I can add some other query to a get_terms() function?

I have a Custom Post Type that uses the default category, the same as the posts, and some other post types in my site. How can I list all non-empty categories from the custom post type?

For instance, if I have categories “Cat 1”, “Cat 2" and “Cat 3” and I have a default post with a category of “Cat 1", and a custom post with categories “Cat 2” and “Cat 3". How would I write a function that would return “Cat 2” and “Cat 3"?

It seems like the get_terms() functions don’t support a post_type argument. Is there a way I can add some other query to a get_terms() function?

I know that it is possible to hide unused terms:

$terms = get_terms( array(
    'taxonomy' => 'category',
    'hide_empty' => true, <-----
) );

However this hides empty for all post types, I'd like to hide empty for just a custom post type.

Source Link
Djave
  • 258
  • 4
  • 25

List non-empty categories from a custom post type

I have a Custom Post Type that uses the default category, the same as the posts, and some other post types in my site. How can I list all non-empty categories from the custom post type?

For instance, if I have categories “Cat 1”, “Cat 2" and “Cat 3” and I have a default post with a category of “Cat 1", and a custom post with categories “Cat 2” and “Cat 3". How would I write a function that would return “Cat 2” and “Cat 3"?

It seems like the get_terms() functions don’t support a post_type argument. Is there a way I can add some other query to a get_terms() function?