sticky post limited to 3 but code is still showing all sticky posts
-
Hi people,
I have added a code to a custom page template to display only 3 sticky posts.
But the code is showing all the sticky posts from the db.
Below is the code<?php
$sticky=get_option( ‘sticky_posts’ );// example args
$args = array( ‘posts_per_page’ => 3, ‘post__in’ =>$sticky );// the query
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?><!– start of the loop –>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?><h2><?php the_title(); ?></h2>
<?php endwhile; ?><!– end of the loop –>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( ‘Sorry, no Sticky post found.’ ); ?></p>
<?php endif; ?>
- The topic ‘sticky post limited to 3 but code is still showing all sticky posts’ is closed to new replies.