I have two post types
- Documents
- News Items
with categories for each post type,
- Documents -- PDF, Word, Excel
- News Items -- Articles, Releases
BUT they share the same tags.
- Documents -- BOSS, EFF, CDF
- News Items -- BOSS, EFF, CDF
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
- Documents
- News Items
with categories for each post type,
- Documents -- PDF, Word, Excel
- News Items -- Articles, Releases
BUT they share the same tags.
- Documents -- BOSS, EFF, CDF
- News Items -- BOSS, EFF, CDF
How can I retrieve a list of the categories whose posts( or post count. regardless of post type) have a specified tags e.g.
Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Jun 5, 2020 at 15:17 KendallKendall 1891 gold badge1 silver badge10 bronze badgesBOSS -- PDF(2), Releases (1)
CDF -- Articles (1), Excel (1)
1 Answer
Reset to default 0After 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']);