WordPress Last 10 Sticky Post Tutorial

WordPress sticky post concept can be very confusing. Sticky posts are posts set to always show when a query returns. If you search the WordPress sticky post hides on the internet you can see that there are not many examples. I will try to illustrate this with an example. You can understand how by examining the following code example. You can try the following code in your own theme in the themes folder

If you dont want sticky post in your wp_query try it

$new_query = new WP_Query(array(
    'ignore_sticky_posts' => true
) );

If you want last 10 sticky post in your wp_query try it

<?php $new_query = new WP_Query(array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 10,
    'ignore_sticky_posts' => true,
    'post__in' => get_option('sticky_posts'),
));
if ($new_query->have_posts()) :
    while ($new_query->have_posts()) : $new_query->the_post(); ?>
        <a href="<?php the_permalink(); ?>"
           title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('medium'); ?></a>
    <?php endwhile;
    wp_reset_postdata();
endif; ?>

2 Comments

  • zvodret iluret


    It’s actually a cool and useful piece of info. I’m satisfied that you shared this helpful information with us. Please stay us up to date like this. Thanks for sharing.

    reply
  • Delman


    Great site you have here but I was wanting to know if you knew of any discussion boards that cover the same topics discussed here? I’d really love to be a part of group where I can get advice from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Many thanks!

    reply

Leave a Reply

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