How To Show Posts Without Using setup_postdata( )

Share Now


<?php 
$paged = get_query_var( "paged" )?get_query_var( "paged" ):1;
$post_per_page = 1;
$post_ids = array( 12,9,18 );
$_p = get_posts(array(
	'posts_per_page'	=> $post_per_page,
	'post__in'		=> $post_ids,
	'orderby'		=>'post__in',
	'paged'			=> $paged	
));

foreach ($_p as $p) {
//setup_postdata( $post );
?>

<div class="post" <?php post_class( ); ?> >
	<div class="container">
		                    
		 <div class="row">
		      <div class="col-md-12">
                      <h3><?php echo apply_filters( "the_title",$p->post_title ); ?></h3>
									
		</div>

		                        <div class="col-md-12">
		                            <p>
		                               <?php

		                                if(has_post_thumbnail( )){
		                                    the_post_thumbnail( 'large', array( "class"=>"img-fluid single-post-highlight-image" ) );
		                                }

		                               ?>
		                            </p>



		                            
		                     		


		                        </div>

		                    </div>

		                </div>
		            </div>
		        <?php }

		        	wp_reset_postdata();

		        ?>

Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert