Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

WordPress Fetching Latest 5 Post using WP_Query()

WordPress Fetching Latest 5 Post using WP_Query()

This post  is all about how to fetch WordPress’s latest 5 post in descending order suing WP_Query(). As we know WordPress is now world best blogging tool and CMS, extremely used for creating Website. Sometime when we are working on custom template and want to so show worpress lates 5 / 3 / 4 post in block we can use wordpress’s function WP_Query(), code is given block and I don’t think its need any explanation but somehow you find it difficult to understand then please comment, I will explain through comment’s reply.

Code for Fetching WordPress Latest 5 post in Descending order

$query = new WP_Query(array('post_type'=>'post','posts_per_page=>5','orderby' => array( 'id' => 'ASC' )));
while($query->have_posts()): $query->the_post();

<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="post-entry">
<a href="<?php echo get_permalink($post->ID);?>">
the_post_thumbnail( 'thumbnail', array(
'class' => 'img-full'
echo '<img src="'.get_template_directory_uri().'/img/thumb.png" class="img-full" alt="No Image">';
<h2> <a href="<?php echo get_permalink($post->ID);?>"><?php the_title();?></a> </h2>
<ul class="entry-meta">
<li> <i class="fa fa-user"></i> <?php the_author(); ?> </li>
<li><i class="fa fa-calendar"></i> <?php the_date(); ?></li>
<?php echo the_excerpt(); ?>
<a class="btn btn-primary" href="<?php echo get_permalink($post->ID);?>">Read More </a>

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments