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 2 custom post types: "Services" and "Works" and they both have a same taxonomy 'Genre'. Now the taxonomy 'Genre' has as term called 'novice'. 5 Recent posts under "Works" which has the term 'novice' (under taxonomy 'Genre') has to be queried on the post pages of "Services" which has the term 'novice' (under taxonomy 'Genre'). There will be 50 terms under the taxonomy.

share|improve this question
add comment

1 Answer

Assuming you want it for all the terms in the 'Genre' taxonomy. In the loop on the single Service post page, put this code:

<?php
$the_terms = get_the_terms( get_the_ID, 'genre' );
if(isset($the_terms) && !empty($the_terms)){
    foreach($the_terms as $the_term){
        $the_terms_slugs[] = $the_term->slug;
    }
}

$works = get_posts(array(
                                'post_type' => 'works',
                                'posts_per_page' => 5,
                                'tax_query' => array(array(
                                    'taxonomy' => 'genre',
                                    'field' => 'slug',
                        'terms' => $the_terms_slugs
                                )));

//This will print the works which have the same genre as the current post
print_r($works_query);
?>

If you want it only for 'novice', let me know and I'll modify the code.

share|improve this answer
    
What I want to do is that in the single-service page it should query the 5 recent posts of the same taxonomy term what the selected service page has but the post type will be different. In this case it should query 5 recent posts of the term 'novice' from the 'Works' post type. I hope the above does the same. –  Anurag Ahuja Jun 28 '12 at 19:59
1  
Yes! Thats what my code above does... try it. –  Rutwick Gangurde Jun 29 '12 at 5:57
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.