Query Anything On WordPress Anywhere

[ad_1]

<?php
$args = array(
      'posts_per_page'   => '3',
      'post_status'   => 'publish',
    );
$recent_posts = wp_get_recent_posts( $args );
// Loop each post
foreach( $recent_posts as $recent ) {
  echo get_the_title($recent["ID"]);
  echo $recent["post_content"];
}
wp_reset_query();
?>

Refer the WP_Query class reference for a complete list of arguments.

Another Approach

<?php 
$my_query = new WP_Query( array(
  'posts_per_page'  => 3,
  'post_status'  => 'publish',
  'paged'  => get_query_var('paged', 1),
));
  
while ( $my_query->have_posts() ) : $my_query->the_post();
  
  post_class();
  the_title();
  the_permalink();
  the_excerpt();
  
endwhile;
wp_reset_query();
?>

[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads