How to exclude current WordPress post from WP Query

Heres a little WordPress snippet that allows you to exclude the current WordPress post from the WP Query – i.e. list of recent posts, more posts from the same category, etc. What the snippet does, is getting the ID of the current post and then use this post ID to exclude current post form being included in the query.

Instructions
Add this code to your WordPress theme template files where you usually use your queries.

Comments

Leave a Reply

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

Snippet Info

Tested with Wordpress v. 5.0
Last Modified: 08.06.2019
Last Reviewed: 08.06.2019

How to exclude current WordPress post from WP Query
3.3 (65.71%) 7 vote[s]
Please report broken snippets.
Report Broken Snippet