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.

OK - Looked everywhere for this one.

Details:

Custom Post Type #1 = 'product' > registered taxonomy 'productranges'

Custom Post Type #2 = 'testimonial' > registered taxonomy 'testimonials'

Both CPTs share categories 'Complete Food' , 'Treats', etc.. for example

Question:

How can I display a random post excerpt of the same shared-category from a 'Testimonial' post into 'Product' post? In a sense linking the Testimoinals to the Products.

I've used the following but it only shows a random post from all the categories, I need it to output from the current-shared category being viewed:

<?php
$posts = get_posts('post_type=testimonial&issue=$issueid&post_status=publish&numberposts=1&orderby=rand');

foreach ($posts as $post) : setup_postdata($post); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt('<div class="readmore">'); ?><a href="/testimonials">read more...</a> 

<?php endforeach; ?>
<?php

//Reset Query
wp_reset_query();?>

Cheers if you can help!

share|improve this question
    
Have you tried putting your get_posts in an array? –  fdsa Jun 27 '12 at 22:05
    
The problem is I'm not sure how to call the current-page's taxonomy dynamically in order for the one template to serve all products. –  Beags Jun 27 '12 at 22:29
    
Is the taxonomy a category? –  fdsa Jun 27 '12 at 23:48
    
Yes - they are categories. The top Taxonomies registered are 'productranges' and 'testimonials'. –  Beags Jun 28 '12 at 8:04
    
Edited initial post to be more clear... –  Beags Jun 28 '12 at 9:29

1 Answer 1

You need to get_the_category() of the product post and then set category in get_posts() to that category's $category->term_id.

share|improve this answer
    
Have sorted it (well - kind chap over at Wordpress.org nailed it):link –  Beags Jun 29 '12 at 9:59

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.