I have this weird thing to do and I have no idea how to do it. Ok, so:

I have two custom taxonomies: collections and categories (both are prefixed, but for the sake of simplicity, I'll use these short names). A post will have a category and will be added into a collection.

What I have to do is to display all posts from a specific taxonomy - categories (already did this) and only show collections terms that have posts in the selected category. Some kind of hide_empty but based on another taxonomy. Make sense?

Since I use WPML plugin (that is known for adding stuff into sql query), I would like a solution that not involve the rewrite of the whole query.

So, any idea would be welcomed. Thanks!


You can try getting all the posts IDs from the first taxonomy

$objects = get_posts( array( 'category' => 'history', 'numberposts' => -1, ) );
foreach ($objects as $object) {
    $objects_ids[] = $object->ID;

Then get the terms from the second taxonomy associated with them:

$collections = wp_get_object_terms( $object_ids, 'collections' );
|improve this answer|||||
  • I did, no luck. I need to fetch terms, not posts. I'll probably end by converting second taxonomy into hierarchies for the first tax. – Ionut Staicu Sep 29 '12 at 9:26
  • Aaaah. So you need to display all posts from category history and show (maybe on the side) just collections from this category. – Dan Ștefancu Oct 1 '12 at 8:02
  • Yes. I decided to merge both taxonomies (as hierarchical terms), since I haded no good reason to split them in two. – Ionut Staicu Oct 1 '12 at 9:00
  • You can run into problems if you need the same collection under multiple categories. See the updated answer above. – Dan Ștefancu Oct 1 '12 at 10:08

I did something that sounds familiar with your case and the easiest way to do it was using the Posts 2 Posts plugin.

|improve this answer|||||
  • 1
    Can you give me more details on that? Maybe a quick example? – Ionut Staicu Sep 28 '12 at 16:08

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.