Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers 2

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' );
share|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
add comment

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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