I'm currently using the following bit of code to display related posts on my single template.
<?php
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>5, // Number of related videos that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<section id="related-videos"><h3><span>Related Videos</span></h3><ul>';
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<li>
<a class="related-thumb" href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('related-thumb'); ?></a>
<section class="related-content">
<a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</section>
</li>
<? }
echo '</ul></section>';
}
}
$post = $orig_post;
wp_reset_query();
I'm wondering if there is a way I can pull tags from only a certain post type. Maybe adding something like 'post_type=videos'
somewhere? Not sure where, though. Can someone help me out? Thank you.