Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Exclude Latest Post from the WordPress Post Loop

Last updated on by
Elegant Themes
How to Exclude Latest Post from the WordPress Post Loop

Excluding latest posts from the loop and/or offset posts in the loop is one of the things that comes in handy when editing or designing themes. In this article we will show you how you can use the offset parameter in wp_query function to exclude latest posts from the WordPress post loop.

First you will need to find the loop that you are working with. Then you will need to add the following parameter:

query_posts('posts_per_page=5&offset=1');

This query is telling the loop to only display 5 posts which follow the most recent post (1). The important part in this code is “offset” and this magic word is doing the whole thing.

Your loop code should look like:

<?php
query_posts('posts_per_page=6&offset=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

This should be it. If you have any questions feel free to ask via comments.

Source: WP Codex


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. space says:

    Solution is work fine, Thanks. but pagination broke after applying this code, I have tried but not able to work with correct pagination. Any solution to pagination ? .

  2. Sabi Maharjan says:

    I have used two plugins. One is “Recent facebook post” to show recent posts in wprdpress and “Facebook publish page” to publish my wordpress posts in facebook . Now I want exclude the recent post of the facebook that was already posted from my wordpress posts .

    How can I do it ?

    • WPBeginner Support says:

      For that your plugin posting content from your Facebook page should have a check to see if a post was already published from WordPress to Facebook. We do not recommend users to directly edit plugin files. However, if you are comfortable editing php files then you can fork the plugin as a new plugin and then add the code to accomplish this.

  3. Pastor Wynn says:

    Thanks for the great tip. I had spent hours trying to figure this out, and you made it so simple!

  4. Gu-ens says:

    Thanks a lot.
    the ‘post__not_in’ option does not work in wordpress 3.5

  5. Jim says:

    Hmm, when i tried this code on a category page loop, it couldn’t keep the posts for only that category, instead it acted as if it was the front page loop and displayed all posts.

  6. Amin says:

    Thank you so much man! This helped a lot!

    Regards!

  7. Fernando says:

    Thanks a lot!! very usefull tip!

  8. GangeshMatta says:

    Thanks!

  9. PabloCovarrubias says:

    hello, i just have one question, when i do this, pagination doesen0t work anymore, how can i fix this?

    thanks, other than that, it works perfectly!!

    cheers!

    • space says:

      Yes, pagination not working. you have found any working solution for pagination, I am still searching .. :(

  10. Jon says:

    Thanks so much for this! I couldn’t figure it out at all but this worked perfectly.

  11. Wordpwess says:

    Is there a way to offset a post from one cat?

    E.g I want to show all posts apart from the LATEST post of category x

  12. Luka says:

    Thanks mate, you save my day :)

  13. Khurram says:

    “query_posts(‘posts_per_page=6&offset=1′);” this is not worked for me , while i am using the WP-PageNavi plugin for page navigation. :(

  14. Ken says:

    Thanks for the info. Worked well :) Though, I’m encountering another issue for another site I’m currently doing. Is there a way to exclude from the loop only the latest post of a particular category?

    Thing is, I’ve a blog that publishes podcasts. The front page highlights the most recent podcast – posts are published under category: Podcast – via its own styling. At the same time, the front page also shows the last 5 most recent posts, of which may include posts under the category “podcast”. I just don’t want to show in the loop the most recent post published under “Podcast” simply because it’s already featured with it’s own styling. Hope you can help me out. thanks!

    • Editorial Staff says:

      You can exclude all posts from the category “postcast” from your loop if you want. But there is no simple way of excluding just the latest post.

  15. Joffrey says:

    Thanks for the tip!
    But I was wondering if there is also a way to exclude the post that is currently showed on screen.

    If yes, can you tell me how to do this?

    Thanks in advance!

    • Editorial Staff says:

      Don’t really understand your question? Which screen?

      • Joffrey says:

        One of my pages displays first of all the latest or current post the user is viewing.

        The current post is called by the loop.

        Below this post I want to display the excerpts of other previous posts without the current post displayed in this list.

        The previous post-excerpts are called by query_posts:

        query(‘showposts=3&cat=5′);
        while($previousPosts->have_posts()) : $previousPosts->the_post();
        ?>

        As you can see I call 3 posts(excerpts) from category 5 which displays three posts from category News. This seems ok but within these 3 post-excerpts, the current post which is called by the loop is also in this list.
        Do you know a way to exclude the current post within this list?

        Thanks again!

        • Editorial Staff says:

          You can add offset=1 in the query to skip the first post.

        • Joffrey says:

          Thanks again for the quick response!
          However, I did try the offset=1 in the query, only thing is that when you press an older post, you get to see the older post in the main loop, within the list excerpts the latest post is excluded, but the older post which is now the current post is still in the excerpts list.

          Any idea how to exclude not the latest but the current post?

          Thanks so far already :)

        • Editorial Staff says:

          Email us the live link to the site, so we can see exactly whats going on. Use the contact form for email.

  16. Bilal Ahmed says:

    Thank you so much for this piece as i was looking for a way to exclude 4 latest posts form my home page and i got answer by this articles and i have replaced (query_posts(‘posts_per_page=6&offset=1′);) by query_posts(‘posts_per_page=6&offset=3′); and its done :)

  17. Jeremy says:

    Where exactly do you put this code to remove al posts but the sticky on the main page.

    Thanks,

    • Editorial Staff says:

      That is a multi-step process. First you would need to have a custom page template. Second you would need to create that custom page, your front page. Then you would run a query on that custom template showing only sticky posts.

  18. dominik says:

    Thanks, it was exactly what I was looking for! Thanks for any other hints.

  19. Morning Copy says:

    Thanks for this. Nice solution for magazine-style layouts.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.