Wordpress: how can I iterate over a list of message identifiers?

I have an array full of message identifiers, such as $post_id = array(3,56,89,98);Now I just need to display the message details in a table format. How can I build a loop for wordpress here? I apologize for my newcomers to Wordpress and be gentle. I really need some direction.

+5
source share
3 answers

I 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; ?>
+5
source

In fact, I think something is wrong with Umesh's answer. Instead:

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

It should be:

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

Right?

+6
source

, query_posts. - query_posts( array( 'post__in' => $post_id ) ); .

WP_Query .

+4

All Articles