Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save curtismchale/1172303 to your computer and use it in GitHub Desktop.
Save curtismchale/1172303 to your computer and use it in GitHub Desktop.
Shows the related content on a WordPress site using Relations post type
function tan_show_related_content( $postid, $post_type ) {
global $wp_query, $post;
// Related IDs for this view ?
$ids = rpt_get_object_relation( $postid, $post_type );
if( $ids == false || empty($ids) )
return false;
$items_query = new WP_Query( array(
'post__in' => $ids,
'post_type' => $post_type,
'post_status' => 'publish',
'showposts' => 1,
) );
/*
<ul class="related-school profile">
<li><strong>Highschool Name: </strong></li>
<li><strong>Highschool City: </strong></li>
<li><strong>Highschool State: </strong></li>
</ul>
*/
if ( !$items_query->have_posts() ) {
echo '<p class="no-result">'.__('No items actually for this custom type.', 'relations-post-types').'</p>';
} else {
echo '<ul class="relations-list">' . "\n";
while ($items_query->have_posts()) : $items_query->the_post();
?>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php
endwhile;
echo '</ul>' . "\n";
}
wp_reset_postdata();
}
// show in the post
tan_show_related_content( $post->ID, 'content_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment