Hello,
I have a CPT called ‘videos’ and another CPT called ‘instructors’.
I have created a Post Object custom field, called ‘instructor’.
On the instructorS single page i want to query a list of videos that have that instructor assigned to them.
This is my code so far:
<?php
$video_id = $post->ID;
$posts = get_posts(array(
‘posts_per_page’ => -1,
‘post_type’ => ‘videos’
));
?>
<?php if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<?php
$post_objects = get_field(‘instructor’);
if( $post_objects ): ?>
<?php foreach( $post_objects as $post_object): ?>
<?php $instructor_id = $post_object->ID;?>
<?php endforeach; ?>
<?php endif;?>
<?php if($instructor_id == $video_id) :?>
<div class=”col-xs-6 col-md-4 curs_instructor”>
” title=”<?php the_title(); ?>”>
<div class=”instructor_video_slide”>
<?php the_post_thumbnail(‘instructor-thumb’, array(‘class’ => ‘aligncenter instructor_img’)); ?>
<div class=”instructor_video_slide_title”><?php the_title();?></div>
</div>
</div>
<?php endif;?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
It works ok, the only issue is that if a video has more that 1 instructors assigned, it will only show 1, instead of all.
Can you please help me?