Support

Account

Home Forums Feature Requests Add ability to exclude drafts from Relationship field Reply To: Add ability to exclude drafts from Relationship field

  • ACF actually does have this feature (though I didn’t realize it until your question raised my curiosity).

    You can filter relationship query results using the filters ‘acf/fields/relationship/query’, ‘acf/fields/relationship/query/name={{field_name}}’, and ‘acf/fields/relationship/query/key={{field_key}}’ in increasing specificity. So to get only published posts, you would have something like:

    
    add_filter('acf/fields/relationship/query/name=your_relationship_name', 'relationship_options_filter', 10, 3);
    
    function relationship_options_filter($options, $field, $the_post) {
    	
    	$options['post_status'] = array('publish');
    	
    	return $options;
    }