Query Loop Exclude Current Post keeps the post someone is reading out of your Query Loops. Your “related posts” section stops recommending the page they’re already on.
Before you start
- WordPress 5.8.3 or later
- PHP 5.6 or later
- The block editor. The toggle is added to the core Query Loop block.
Install
- In your WordPress dashboard, go to Plugins → Add New Plugin.
- Click Upload Plugin.
- Choose the plugin zip file.
- Click Install Now.
- Click Activate.
There’s no settings page. You turn it on per Query Loop.
How to use
Exclude the current post from a Query Loop
- Add a Query Loop block, or select one you already have. This works well in a single post template or a synced pattern used below your posts.
- Make sure the loop uses a custom query, not the template’s query. The toggle is hidden when the loop inherits its query from the template.
- In the block settings sidebar, open the Exclude Current Post panel.
- Turn on Exclude Current Post (“Excludes the current post from the loop when enabled.”).
- Save.
On the front end, the loop now skips whichever post is being viewed. When you edit a single post, the editor preview skips that post too.
Block options
- Exclude Current Post: leaves the post being viewed out of this loop’s results. Default: off.
Developer reference
Coming soon: the hooks, filters and functions you can use with this plugin from your theme or a code snippet.
FAQs
Why don’t I see the toggle?
The Exclude Current Post panel only appears on a Query Loop that uses its own query. When the loop inherits the query from the template, the panel is hidden.
Does it work with hand-picked posts?
Yes. If another plugin (such as a post selector) sets a specific list of posts for the loop, the current post is removed from that list as well.
Does it work with other exclusions on the loop?
Yes. The current post is added to any posts the loop already excludes, rather than replacing them.