I’m working on a Movie Database based on WordPress.
I’ve 2 main Custom Post Type, Movie and Director, with relative entry. In Movie, the director is called by a custom taxonomy and automatically linked to the relative Custom Post Type page with photos, bios, etc…
In the Director page, I need to recall the Movie related to this director.
<?php
$custom_terms = get_terms('director');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'movie',
'tax_query' => array(
array(
'taxonomy' => 'director',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2 class="terms-title">'.$custom_term->name.'</h2>';
echo '<ul class="post-list">';
while($loop->have_posts()) : $loop->the_post();
echo '<li><a href="'.get_permalink().'" title="'.get_the_title().'" target="_blank">'.get_the_title().'</a> </li>';
endwhile;
echo "</ul>";
}
}
?>
I’ve write this code but actually get all director terms and listing movies for all directors.