Skip to main content
1 of 2
dtj
  • 173
  • 8

Get Unique Categories - Group By?

I have 2 separate groups of Categories that a post can be classified in: Client & Medium.

I'm trying to display all the Clients (if they have posts), and any Mediums that those posts may belong to.

The problem I'm running into is this: Lets say a 3 posts are associated with Client A. When I'm in the loop, and gathering all the Categories for each post, I get 'Client A' 3 times, instead of just once (as I want it).

The same is true with the Medium category as well.

I want to display only:

a) the unique / distinct Clients (that have posts)

b) the mediums that those posts are categorized by, per client.

What's the best way of going about this? If I'm in the Loop, is there a way to only pull unique Categories? Or do I have to gradually put them all in an array, and check that they don't exist before adding a new one?

How about using some sort of Group By clause?

dtj
  • 173
  • 8