How to Exclude Current Post from Recent Posts when using Repeater in Oxygen
In a previous tutorial, I showed how the current post can be excluded from the list of recent posts when we are on a single post page using a Code Block here.
This members-only tutorial shows how the same can be done but when using Oxygen's Repeater component to output the posts list.
![](https://wpdevdesign.com/wp-content/uploads/2020/07/latest-posts-repeater-exclude-current-post-oxygen-1024x770.jpg)
By default the current post may appear in the recent posts list:
![](https://wpdevdesign.com/wp-content/uploads/2020/07/recent-posts-repeater-current-post.jpg)
We can use pre_get_posts
action hook to set post__not_in
for the query to the current post's ID even if the query is a custom one like in the case of a Repeater thereby preventing the current post from appearing in the latest posts.
Step 1
Edit the Oxygen Template that applies to singular posts.
Add a Repeater component and build the Div for each post. In my test site, I set up the featured image and a Div to appear next to each other with the Div having linked post title and excerpt showing 5 words.
If you would like to paste the Repeater from my test site as a starting point, follow these steps:
a) Install and activate Code Snippets plugin.
Go to Snippets > Add New.
Title: Custom excerpt
Code:
This is a premium members-only content.
To view the rest of the content, please sign up for membership ($47/month or $599 one-time).
Already a member? Log in below or here.