Let's cut right to the chase: I have two custom post types: interviews and people. They both have custom taxonomy names. In interviews there is a video interview with one particular person along with the transcript of the video. In people, there is a short biography and a photo of that person.
On my home page I want to display randomly picked interview: title, short excerpt of the video interview transcript - and I need a photo of that person. Which I need to pull from the custom post type for that person which is people custom post type.
The way I figure it out is that I need a query within a query. First is to pick a random interview and then to somehow find the people post with the same names term as that particular random interview.
Can someone help me with this?
@toscho ok, so this is my code with post 2 post plugin:
<?php query_posts(
array (
'post_type' => 'interviews',
'posts_per_page' => 1,
'orderby' => 'rand',
)
);
while ( have_posts() ) : the_post();?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php
// Find connected pages
$connected = new WP_Query( array(
'post_type' => 'people',
'connected_from' => get_queried_object_id(),
)
);
// Display connected pages
while ( $connected->have_posts() ) : $connected->the_post();?>
<h2>Person in this interview: <?php the_title();?></h2>
<?php endwhile;
// Prevent weirdness
wp_reset_postdata();?>
<?php endwhile; wp_reset_query();?>
It still doesn't work. It displays all the peoples' names, no matter which one is connected to that interview