I have two post types
with categories for each post type,
BUT they share the same tags.
How can I retrieve a list of the categories whose posts( or post count. regardless of post type) have a specified tags e.g.
BOSS -- PDF(2), Releases (1)
CDF -- Articles (1), Excel (1)
I have two post types
with categories for each post type,
BUT they share the same tags.
How can I retrieve a list of the categories whose posts( or post count. regardless of post type) have a specified tags e.g.
BOSS -- PDF(2), Releases (1)
CDF -- Articles (1), Excel (1)
After some research I came up with the following
// Get the posts in that category with the required tag
$args = array(
'post_type' => ['documents','news'],
'fields' => 'ids', // Only get post IDs
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'forms',
'field' => 'slug',
'terms' => $symbol
)
)
);
$posts_array = get_posts( $args );
$categories = wp_get_object_terms($posts_array, ['sources','articles'], ['fields' => 'id=>name']);