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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.