# Stop ACF Fields Linking a Post to Itself

> Removes the post being edited from the choices of ACF relationship and post object fields.

- Type: PHP
- Runs: Admin only
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: acf, relationship, editor
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/acf-post-object-exclude-current/

## Code

```php
$wpide_acf_exclude_self = function ( $args, $field, $post_id ) {
    if ( is_numeric( $post_id ) && $post_id ) {
        $args['post__not_in'] = array_merge( (array) ( $args['post__not_in'] ?? array() ), array( (int) $post_id ) );
    }

    return $args;
};

add_filter( 'acf/fields/relationship/query', $wpide_acf_exclude_self, 10, 3 );
add_filter( 'acf/fields/post_object/query', $wpide_acf_exclude_self, 10, 3 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Stop ACF Fields Linking a Post to Itself" 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/
