Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 757
Samik Chattopadhyay Avatar asked Dec 17 '11 13:12

Samik Chattopadhyay


People also ask

How do I get a list of all posts in WordPress?

You have to use post_per_page='-1' to retrive all the posts. $args = array( 'post_type'=> 'post', 'orderby' => 'ID', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1 // this will retrive all the post that is published ); $result = new WP_Query( $args ); if ( $result-> have_posts() ) : ?>

How do I print a WordPress post ID?

Get Post ID Using the get_the_ID() and the_ID() Functions The get_the_ID() and the_ID() functions display the current post's ID. The main difference between the two functions is that get_the_ID() returns the post ID without displaying it, while the_ID() always prints the post ID.

What is a posting loop?

The loop, or WordPress loop or simply loop, is PHP code that displays WordPress posts. The loop is used in WordPress themes to display a list of posts in a web page. Inside the loop there are some functions that are run by default to display posts.


1 Answers

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?

like image 87
MACC Avatar answered Oct 21 '22 04:10

MACC