Created
June 18, 2012 14:25
-
-
Save nickhempsey/2948630 to your computer and use it in GitHub Desktop.
Reverse Relationship ACF
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 | |
/* --------------- 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