I have a partial that I call around the website at various points. This partial simply displays the latest Post.
It looks like so:
<?php
$args = array(
'posts_per_page' => 1,
'order' => 'desc'
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
if (has_post_thumbnail( $post->ID ) ){
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'home-news-thumbnail' );
}
?>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php echo get_the_title(); ?></h3></a>
<?php if(!empty($featured_image)): ?>
<a href="<?php echo get_the_permalink(); ?>">
<img src="<?php echo $featured_image[0]; ?>" alt="" width="250" class="pull-left">
</a>
<?php endif; ?>
<p>
<?php echo get_the_excerpt(); ?>
</p>
<a href="<?php echo get_the_permalink(); ?>" class="btn btn-brand-dark">more</a>
<div class="clearfix"></div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
This works fine until I 'Sticky' a post. Then I get 2 posts instead of 1.
How can I amend all queries so that posts_per_page
has the requested number of posts, regardless of sticky posts?
So in the example above, I'm currently getting 2 posts (despite requesting 1), but I want the latest post, whether that's a sticky post or not.
I know about ignore_sticky_posts
parameter, but that will ignore the sticky post, which I don't want to do. If there's a sticky post it should be first.