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.
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() ) : ?>
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With