0

I have two post types

  1. Documents
  2. News Items

with categories for each post type,

  1. Documents -- PDF, Word, Excel
  2. News Items -- Articles, Releases

BUT they share the same tags.

  1. Documents -- BOSS, EFF, CDF
  2. 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)

1 Answer 1

0

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']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.