2
votes

I have a field group attached to a custom post type. It contains a 'status' select input which the user can choose an option from in the wp admin area.

I also have a front end form using the same field group so lower level users can create a post on the front end, however they are not allowed to choose a 'status' they must accept the default.

I setup a default value and made it required, then excluded the field from the front end form using the settings arg. This didn't work, it just left the field value empty.

Alternatively is there a way to output the field as a hidden input on the front end?

1
“a front end form using the same field group” - how exactly, are we talking via some plugin, like Advanced Forms? Check out what hooks are available with the solution you are using, to manipulate the form before it gets rendered. The mentioned plugin f.e. has the possibility to exclude fields from rendering when you do that via a function call (advancedforms.github.io/guides/basic/displaying-a-form), and a hook that lets you add hidden fields easily, advancedforms.github.io/actions/af-form-hidden_fields04FS

1 Answers

0
votes

you can do like this (here my acf field slug is "id_label") :

// set default value
add_filter('acf/load_field/name=id_label', function($field) {   

    $field['default_value'] = '666';

    return $field;
});

// hide the field in frontend form
add_filter('acf/prepare_field/name=id_label', function($field) {
    
    if(!is_admin()) {
        $field['wrapper']['class'] = 'hide';
    }

    return $field;
});