# Elementor Posts Query: Exclude the Current Post

> Adds a custom query ID "wpide_exclude_current" for Elementor Pro's Posts and Loop Grid widgets that leaves out the post being viewed, ideal for "More articles" sections.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: elementor, query, posts, related
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/elementor-query-exclude-current-post/

## Code

```php
add_action( 'elementor/query/wpide_exclude_current', function ( $query ) {
    $current = get_queried_object_id();

    if ( ! $current || ! is_singular() ) {
        return;
    }

    $exclude = (array) $query->get( 'post__not_in' );
    $exclude[] = $current;
    $query->set( 'post__not_in', array_map( 'absint', $exclude ) );
} );
```

## Notes

In the widget's Query section, type wpide_exclude_current in the Query ID field.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Elementor Posts Query: Exclude the Current Post" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
