# Only Published Posts in ACF Relationship Fields

> Limits the choices in ACF relationship and post object fields to published content, newest first, so editors cannot link to drafts.

- 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-relationship-published-only/

## Code

```php
$wpide_acf_published_only = function ( $args ) {
    $args['post_status'] = 'publish';
    $args['orderby']     = 'date';
    $args['order']       = 'DESC';

    return $args;
};

add_filter( 'acf/fields/relationship/query', $wpide_acf_published_only );
add_filter( 'acf/fields/post_object/query', $wpide_acf_published_only );
```

## Notes

Applies to every relationship and post object field; add /name=your_field to the hook names to target one.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Only Published Posts in ACF Relationship Fields" 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/
