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:

Comments

2 responses to “ACF: Exclude drafts from Relationship field”

  1. Tom Avatar
    Tom

    if it’s possible to exclude all post without a thumbnail?

    1. Allison Avatar

      Good question! Yup, you can query for anything with the usual WP_Query parameters – Here’s a snippet exhibiting how.

Leave a Reply

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