WordPress : How can I loop through a list of post ID

I have an array full of post IDs like $post_id = array(3,56,89,98); Now what I have to do is just display the post details in a tabular format. How can I construct the loop for WordPress here? Please apologize my novice knowledge in WordPress and be soft. I really need some direction.

Related posts

Leave a Reply

3 comments

  1. Actually I think there’s something wrong with Umesh’s answer.
    Instead of:

    $post_id = array(3,56,89,98);
    

    It should be:

    $post_id = array( 'post__in' => array(3,56,89,98) );
    

    Right?

  2. i have also started learning php all you need to do something like

    foreach ($post_id as $id) { 
      // do what ever you want to do here
    
    }
    

    Edit

    <?php
    $post_id = array(3,56,89,98);
     $posts = get_posts( $post_id);
     foreach( $posts as $post ) :
      setup_postdata($post);  ?> 
         // you can call use post data inside here like
         <h2 class="title"><?php the_title(); ?></h2>
    <?php endforeach; ?>