Home Forums Backend Issues (wp-admin) New field type: select


New field type: select

  • Hi guys,

    I’m trying to create my first new field type and would appreciate a little help.

    I’ve followed the instructions from ACF’s documentation and used the starter kit to register my new field. The demo input field from the starter kit renders fine, but I’d like to use a select field instead, and that’s where I’m stuck.

    After changing ‘acf_render_field_setting( $field, array(…));’ to render_field_settings ‘type’ => ‘select’, the input field changes to a select field, but no options are being rendered. In fact, it seems as no code was being processed by the render_field( $field ){…} function.

    What is the correct approach to create a select field with dynamically created options?

  • All right, got it.

    ACF doesn’t render any options on ACF’s Field Groups admin page. I went to edit a post that the Field Group is associated with, and all the options of my new field render there.

    I’m fine with it, but it would be interesting to know, why nothing will render on ACF’s Field Groups admin page?

  • So I’ve managed to store my select field’s value, by passing it to a hidden input field, which works fine. But now I’m facing some trouble with the repeater field.

    ACF generates a repeater’s subfield $field[‘name’] and $field[‘ID’], by replacing [acfcloneindex] by an $i integer value, through the use of javascript–see this post for reference.
    I haven’t found a way to get around the [acfcloneindex] riddle yet, but I’m wondering how ACF stores its own select fields values.

    I’m generating the select code of my field using the same structure as ACF, but ACF won’t store the value upon saving the post:

    echo '<select id="' . esc_attr($field['id']) . '" name="' . esc_attr($field['name']) .'" data-ui="0" data-ajax="0" data-multiple="0" data-placeholder="Select" data-allow_null="0">';
    $output .= '<option value="0"></option>';
    foreach($options as $option){
    echo $output . '</select>';

    So the question is, what am I missing? How can I store my select field’s value?

    I figure there has to be a better way than by using hidden inputs, right?

  • I’m not exactly sure where you’re running into a problem. The best advice that I can give you is to open the file for the built in select field and look at what it’s doing. The select field has several extra settings and functions that it runs for showing the field and storing values.

  • After reviewing my field settings, I realized that I had forgotten to change the field type to select. So I guess that must have been it.

    Thank you, John!

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

The topic ‘New field type: select’ is closed to new replies.