ACF: Featured Images and Relationship Field

When using the relationship ACF field, this snippet will exclude items of the specified CPT that don’t have an attached featured image.

Similar to how we can exclude drafts within the relationship field, we can also use the WP_Query arguments to specify the meta query we want (in this case, the existence of the thumbnail ID).

In this example, the CPT is ‘Services’ and ‘services_list’ is the name of the ACF Relationship field.
$options uses the previously mentioned WP_Query arguments.

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

Leave a Reply

Your email address will not be published.