ACF: Exclude drafts from Relationship field

When using the relationship ACF field, this snippet will only show the published items of the specified CPT.

In this example, the CPT is ‘Services’ and ‘services_list’ is the name of the ACF Relationship field.
$options uses the WP_Query arguments used to specify the post status we want.

function cpt_services_relationship_filter( $options ) {
	$options['post_status'] = array( 'publish' );
	return $options;
}
add_filter( 'acf/fields/relationship/query/name=services_list', 'cpt_services_relationship_filter' );
Additional Reading:

2 thoughts on “ACF: Exclude drafts from Relationship field

Leave a Reply

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