Skip to content

Instantly share code, notes, and snippets.

@nickhempsey
Created June 18, 2012 14:25
Show Gist options
  • Save nickhempsey/2948630 to your computer and use it in GitHub Desktop.
Save nickhempsey/2948630 to your computer and use it in GitHub Desktop.
Reverse Relationship ACF
<?php
/* --------------- COMMENTED ------------------- */
// Grab the permalink from current staff page.
// I tried using the post ID's but I ran into a lot of issues.
// The permalink was the most solid solution.
$post_permalink = get_permalink();
// Start the query for all portfolio items
$args = array(
'post_type' => 'portfolio',
'order' => 'DESC',
);
$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
// Start Relationship field
foreach(get_field('team_members') as $post_object):
// Set the permalinks for the associated staffers
$object_permalink = get_permalink($post_object->ID);
// If the permalinks are the same, show the thumbnail from the portfolio page at a custom size
if( $object_permalink == $post_permalink ) :
echo '<a href="'. get_permalink($query->ID). '">' .get_the_post_thumbnail($query->ID, 'portfolio-gallery'). '</a>';
endif;
endforeach;
endwhile;
endif;
wp_reset_query();
/* --------------- UNCOMMENTED ------------------- */
$post_permalink = get_permalink();
$args = array(
'post_type' => 'portfolio',
'order' => 'DESC',
);
$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
foreach(get_field('team_members') as $post_object):
$object_permalink = get_permalink($post_object->ID);
if( $object_permalink == $post_permalink ) :
echo '<a href="'. get_permalink($query->ID). '">' .get_the_post_thumbnail($query->ID, 'portfolio-gallery'). '</a>';
endif;
endforeach;
endwhile;
endif;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment