Exclude Password Protected Posts from Related Posts in single.php
-
Hello, I’m using some custom code based on a snippet found over at WPBeginner to display related posts by category in a 3×3 thumbnail grid at the end of a single post.
I have noticed that password protected posts (which I have hidden everywhere via functions.php) do appear in related posts for their respective categories.
Is there a way to tweak my code (below) in order to filter these out?
Thanks!
<?php $orig_post = $post; global $post; $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> 6, // Number of related posts that will be shown. 'caller_get_posts'=>1 ); $my_query = new wp_query( $args ); if( $my_query->have_posts() ) { echo '<div id="related_posts"><h3>'; _e ('Similar photos', 'site5framework'); echo '</h3><h5><ul class="img-list">'; while( $my_query->have_posts() ) { $my_query->the_post();?> <li><a href="<? the_permalink()?>" rel="bookmark" /><img src="<?php the_post_thumbnail_url( 'standard-thumb' );?>"><span class="text-content"><span><?php the_title(); ?></span></span></a></li> <? } echo '</ul></h5></div>'; } } $post = $orig_post; wp_reset_query(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Exclude Password Protected Posts from Related Posts in single.php’ is closed to new replies.