Support

Account

Home Forums ACF PRO How to remove drafted posts from already selected relationship Reply To: How to remove drafted posts from already selected relationship

  • Hi! I’m used ACF PRO on many my projects!

    We often use custom fields for job postings. We have 2 custom post types – Jobs and Contact person. Both connected by relationship and on Job post we select Contact peson.
    Also we have functionality which send to draft job post if Job date is expired.

    On functions.php i add also functionality which remove possibility to select drafted post in relationship globally. Like this:

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

    My problem is that if we select post and after date is expired we have this post on right side of relationship field, which is bad for coding, because in loop we still have that post.

    On backend i add also checking if post have status “published”. Frontend part is ok, but i wat to hide drafted post on right side of relationship field – see image below. Highlighted part must be hidden!

    Tell me please what is possible!