Reputation: 45
I want to show 4 latest posts from tag "video" in WordPress, how can i do this?
I tried this loop but all i want only 4 latest posts.
<?php query_posts('tag=video'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
no video
<?php endif; ?>
Upvotes: 1
Views: 47
Reputation: 499
Try below Code:
<?php
$query = new WP_Query( array(
'posts_per_page' => 4,
'no_found_rows' => true,
'tag' => 'video'
) );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
// the_title();
endwhile;
wp_reset_postdata();
endif;
?>
Upvotes: 1