Last active
March 10, 2017 15:37
-
-
Save mrpaulphan/fd519887e974c9fb000d59113b08cdfc to your computer and use it in GitHub Desktop.
Reverse Query Relationship for Advanced Custom Fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posts = get_posts(array( | |
'posts_per_page' => 1, | |
'orderby' => 'rand', | |
'post_type' => 'testimonial', | |
'meta_query' => array( | |
array( | |
'key' => 'related_project', // name of custom field | |
'value' => '"' . get_the_ID() . '"', | |
'compare' => 'LIKE' | |
) | |
) | |
)); | |
if ($posts): ?> | |
<section class="testimonial"> | |
<div class="page testimonial__content"> | |
<?php foreach ($posts as $post): | |
setup_postdata($post); | |
?> | |
<blockquote class="testimonial__blockquote"> | |
<div class=""> | |
<p class="testimonial__quote"><?php the_field('testimonial') ?></p> | |
<span class="testimonial__author">-<?php the_title(); ?></span> | |
</div> | |
<span class="testimonial__image"><img src="http://placehold.it/259x169" alt=""></span> | |
</blockquote> | |
<?php endforeach; ?> | |
<?php wp_reset_postdata(); ?> | |
</div> | |
</section> | |
<!-- ./testimonial --> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment