Created
August 25, 2011 23:24
-
-
Save curtismchale/1172303 to your computer and use it in GitHub Desktop.
Shows the related content on a WordPress site using Relations post type
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
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