How to list posts in a Blog page on a particular criteria

  • To Fetch and display all the posts in a page.
    (From the current scenario, it displays title and tag name.)
<?php
$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() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php the_title(); ?> 
<?php the_tags(); ?> 
<?php echo "<br>"; ?>  
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
  • Filter according to tag slug
'tag_slug__in'    => array('popular'),
  • To list only three items
'posts_per_page' => 3

Leave a comment

Your email address will not be published. Required fields are marked *