This is a slider from the index.php pulling the testimonials
<?php
// Let's get in homepage mode.
$post = get_post(505); // My home "page" id = 505
setup_postdata( $post );
/*
Reverse Query on the Post Object Field
*/
$testimonials = get_posts(array(
'post_type' => 'testimonial',
'meta_query' => array(
array(
'key' => 'pages_to_show_testimonial', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123",
'compare' => 'LIKE'
)
)
));
// now get out of homepage mode now that we have our testimonials.
wp_reset_postdata();
if( $testimonials ): ?>
<div class="wrapper">
<div class="testimonial">
<ul class="slides">
<?php foreach( $testimonials as $testimonial ):
// get those id's for the fields
$ID = $testimonial->ID;
$job_title = get_field( 'job_title', $ID );
$company = get_field( 'company', $ID );
$testimonial = get_field( 'testimonial', $ID);
$title = get_the_title($ID);
?>
<li>
<div class="the-testimonial"><?php echo $testimonial; ?></div>
<div class="the-testimonial-name"><?php echo $title; ?></div>
<?php if($job_title != '' ) { echo '<div class="the-testimonial-jt">, '.$job_title.'</div>'; }?>
<?php if($company != '' ) { echo '<div class="the-testimonial-company">, '.$company.'</div>'; }?>
</li>
<?php endforeach; ?>
</ul><!-- slides -->
</div><!-- .testimonial -->
</div><!-- wrapper -->
<?php endif; wp_reset_postdata(); ?>