WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
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

WPBeginner» Blog» Themes» How to Exclude Latest Post from the WordPress Post Loop

How to Exclude Latest Post from the WordPress Post Loop

Last updated on June 21st, 2012 by Editorial Staff
19 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
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

19 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

43 Comments

Leave a Reply
  1. Phil says:
    Jan 9, 2019 at 3:56 pm

    WP Codex…

    > “This should NOT be used within the WordPress loop”

    you have been warned,

    Reply
    • WPBeginner Support says:
      Jan 10, 2019 at 11:12 am

      Thank you for bringing this older article to our attention :)

      Reply
    • Nathan says:
      Jan 18, 2019 at 4:35 am

      Why ? Security breach ?

      Reply
      • WPBeginner Support says:
        Jan 18, 2019 at 10:44 am

        WordPress added newer methods to select specific posts since the creation of this article. If you use this code in the main loop then it edits the main loop of the site is another reason that is stated in the codex.

        Reply
  2. ghazali says:
    Jun 21, 2018 at 4:52 am

    Is there anyway for me to remove only top 3 featured post from the homepage?

    Reply
  3. ivan logan says:
    Oct 28, 2017 at 5:25 pm

    How to remove all posts without featured images(thumbnails), I have 9000 to remover them!

    Reply
  4. Praveen says:
    Oct 6, 2016 at 11:52 am

    Thanks, Good job, Good Solution

    Reply
  5. Matt says:
    Dec 17, 2015 at 5:58 pm

    Beauty post! Simple, clear, and VERY handy. Cheers to you!

    Reply
  6. Dimarj says:
    Nov 11, 2015 at 6:51 am

    ;-) Thanks for this. :-) :-(

    Reply
  7. BGH_ says:
    Oct 22, 2014 at 11:19 pm

    Hey guys, thanks for this article! I want to implement this, but whenever I try I’ve got an strange problem: entries would look like exactly like the frontpage, showing a list of recent post rather than the post itself. My code is slightly different, since is a SMTheme. Any help will be much appreciated. PS: Sorry for posting twice, but the code has printed wrong. Here you go:

    Reply
  8. space says:
    Jan 18, 2014 at 6:49 am

    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 ? .

    Reply
    • Rickie Anand says:
      Sep 9, 2014 at 6:22 am

      apply class to the li as per the number of page and a counter & give style to p1c1 as display:none;

      Reply
  9. Sabi Maharjan says:
    Dec 10, 2013 at 4:26 am

    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 ?

    Reply
    • WPBeginner Support says:
      Dec 10, 2013 at 11:18 am

      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.

      Reply
  10. Pastor Wynn says:
    Nov 18, 2013 at 10:03 pm

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

    Reply
  11. Gu-ens says:
    Jun 7, 2013 at 3:42 pm

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

    Reply
  12. Jim says:
    Apr 26, 2013 at 10:40 am

    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.

    Reply
  13. Amin says:
    Jan 31, 2013 at 3:12 am

    Thank you so much man! This helped a lot!

    Regards!

    Reply
  14. Fernando says:
    Jan 9, 2013 at 11:22 am

    Thanks a lot!! very usefull tip!

    Reply
  15. GangeshMatta says:
    Sep 14, 2011 at 3:41 pm

    Thanks!

    Reply
  16. PabloCovarrubias says:
    Jun 2, 2011 at 8:28 pm

    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!

    Reply
    • space says:
      Jan 18, 2014 at 6:50 am

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

      Reply
      • Kev Bowman says:
        Aug 10, 2015 at 10:24 am

        Did you ever find a solution for this?

        Reply
        • de hams says:
          Sep 2, 2015 at 2:04 am

          pagination do not work on index page most so we can make out own ajax pagination call and mostly query_posts() works for pagination rather then WP_Query()

  17. Jon says:
    May 2, 2011 at 10:15 am

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

    Reply
  18. Wordpwess says:
    May 1, 2011 at 1:27 pm

    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

    Reply
    • Editorial Staff says:
      May 3, 2011 at 6:27 pm

      Yes, you can just select category_in parameter, and add your category ID.

      Reply
  19. Luka says:
    Apr 29, 2011 at 4:55 pm

    Thanks mate, you save my day :)

    Reply
  20. Khurram says:
    Apr 5, 2011 at 2:23 am

    “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. :(

    Reply
    • Editorial Staff says:
      Apr 5, 2011 at 1:22 pm

      what error are you getting?

      Reply
  21. Ken says:
    Dec 9, 2010 at 9:48 am

    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!

    Reply
    • Editorial Staff says:
      Dec 9, 2010 at 11:18 am

      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.

      Reply
  22. Joffrey says:
    Sep 1, 2010 at 10:14 am

    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!

    Reply
    • Editorial Staff says:
      Sep 1, 2010 at 10:30 am

      Don’t really understand your question? Which screen?

      Reply
      • Joffrey says:
        Sep 2, 2010 at 6:52 am

        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!

        Reply
        • Editorial Staff says:
          Sep 2, 2010 at 8:25 am

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

        • Joffrey says:
          Sep 2, 2010 at 8:43 am

          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:
          Sep 2, 2010 at 8:47 am

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

  23. Bilal Ahmed says:
    Aug 2, 2010 at 7:46 am

    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 :)

    Reply
  24. Jeremy says:
    May 18, 2010 at 11:09 am

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

    Thanks,

    Reply
    • Editorial Staff says:
      May 18, 2010 at 11:42 am

      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.

      Reply
  25. dominik says:
    May 14, 2010 at 7:20 am

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

    Reply
  26. Morning Copy says:
    May 6, 2010 at 7:10 pm

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

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
All in One SEO logo
All in One SEO
Improve website SEO rankings with AIOSEO plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
Advanced Coupons
Advanced WooCommerce Coupons
Get 50% off the Advanced Coupons smart coupons plugin for WooCommerce.
Astra WordPress Theme
Astra Theme Coupon
Get 10% OFF on the purchase of Astra WordPress Theme.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.