• Hey

    I want to build an option where in every single-post, there are 3 “realted posts” at the bottom of it.
    So I put this code in the bottom of “content-single.php”:

    <div class="related-posts">
    		$args = array(
    
    				'post__in'      => array(38328, 38359, 323213)
    		);
    		$the_posts = new WP_Query($args);
    		//if ( $the_posts ){
    		echo '<div class="row">';
    		while ($the_posts->have_posts()): $the_posts->the_post();?>
    
    			<div class="col-sm-4">
    				<?php
    				if (has_post_thumbnail()):
    					the_post_thumbnail();
    				endif;
    				?>
    				<?php the_title() . '<br/>'; ?>
    			</div>
    
    		<?php endwhile;
    		echo '</div>';
    		//}
    		wp_reset_postdata();
    
    		var_dump($the_posts);
    		//var_dump($the_query);
    
    		else:
    			echo"no related posts found";
    	endif;
    	?>
    </div>

    But in one post, I get 8 different posts, and in other post I get no posts at all, although I chose only three posts in “post__in”.
    Any idea why that’s happening and how I can make it done?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bring only posts that are from specific id's’ is closed to new replies.