ACF

ACF Form: How to make Post Content field required?

When using ACF Form as a post content editor using the argument 'post_content' => true, ACF will display a virtual WYSIWYG field. Unfortunately the field isn’t natiely required. In some cases it is interesting to make it mandatory.

In theory we should use acf/prepare_field as it is the go-to filter when it comes to modify field parameters before rendering.

But in this case we will have to use an higher hook because of the way ACF create this virtual field. The right hook will be: acf/validate_field. As the virtual field is locally registered during the form generation, we cannot use filters variations, so our target field name _post_content will be the first conditional.

add_filter('acf/validate_field', 'acf_form_post_content_required');
function acf_form_post_content_required($field){
    
    if($field['name'] != '_post_content')
        return $field;
    
    $field['required'] = true;
    return $field;
    
}

 

ACF Hooks

ACF Modules