Support

Account

Home Forums Backend Issues (wp-admin) Exclude Drafts from Post Object field

Solving

Exclude Drafts from Post Object field

  • I want to create a Post Object field containing only posts with status “publish” and I can’t see any option to achieve this…

    The only option I can think of is to directly edit the plugin’s code in core/fields/post_object.php line 93,
    replacing this:
    'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
    by this:
    'post_status' => array('publish'),

    But I prefer not to touch the plugin’s code, because it’ll be overriden if I update it later on and it’s not in my repo…
    So, is there anything else I can do in my own code (e.g., in my functions.php) to achieve the same result?

  • // hide drafts
    function relationship_options_filter($options, $field, $the_post) {
    $options[‘post_status’] = array(‘publish’);
    return $options;
    }
    add_filter(‘acf/fields/post_object/query/name=<YOUR FIELD NAME>’, ‘relationship_options_filter’, 10, 3);

  • I can’t see this function in the ACF code, does it still exist @paulhuisman ?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Exclude Drafts from Post Object field’ is closed to new replies.