Help for Related Posts within Custom Post Type? Not looping
-
Hi WP community –
I’m trying to call Related Custom Posts from directly within my theme as opposed to using a Related Posts plugin, mostly because WPengine doesn’t allow most of them and most of them also don’t work with Related Posts.
I got the following code to work to call 1 related, but I can’t figure out why it’s not looping to call 3? I’m sure I’m missing something simple, but I can’t find it. Any help?
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
<?php if (is_singular( 'team-member' ) ): $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'=>3, // Number of related posts to display. 'caller_get_posts'=>1, 'post_type' => 'team-member', 'taxonomy' => 'team-member' ); $my_query = new wp_query( $args ); while( $my_query->have_posts() ) { $my_query->the_post(); } } ?> <h3 class="related-header">Similar Partners</h3> <div class="relatedthumb"> <a rel="external">"><?php the_post_thumbnail(array(200,200)); ?> <div class="partner-name"><?php the_title(); ?></div> </a> </div> <? $post = $orig_post; wp_reset_query(); endif; ?>
Many thanks!
Btw, the site is https://www.getcredo.com and an example of a page where it will go is https://www.getcredo.com/team-member/john-doherty/
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Help for Related Posts within Custom Post Type? Not looping’ is closed to new replies.