Support

Account

Home Forums Add-ons Repeater Field Dynamic select from options page doesn't save value in Repeater field

Solved

Dynamic select from options page doesn't save value in Repeater field

  • I apologize for how long this is, but I feel in order to get solid help with the problem you guys need as much info as possible. Here is my setup and the problem is defined at the bottom.

    Options Page

    if( function_exists('acf_add_options_page') ){
        acf_add_options_page(array(
            'menu' => 'Filter Groups',
            'title' => 'Filter Groups',
            'parent' => 'edit.php?post_type=custom-post-type-slug',
            'redirect' => false
        ));
    }

    On the options page I have a textarea field with the name attribute set to:

    name => filter_type_values

    Example data:
    0 : First Value
    1 : Second Value

    This allows us to define the values that populate the select box that will appear on the custom post type page for assignment to that post.

    Custom Post Type Page
    On my custom post type edit page I have assigned a custom field group containing a repeater field that has the following sub-fields:

    select field ( gets populated from the textarea on the options page )
    name => filter_type

    This field gets populated using:

    function get_filter_type_values(){
        $values = array();
        $data = get_field('filter_type_values', 'option', false);
        $data = explode("\r\n", $data);
        $data = array_map('trim', $data);
        if( is_array($data) ){
            foreach( $data as $value ){
                $value = explode(" : ", $value);
                $values[$value[0]] = $value[1];
            }
        }
        return $values;
    }
    function acf_load_filter_type_field_choices( $field ){
        $field['choices'] = get_filter_type_values();
        return $field;
    }
    add_filter('acf/load_field/name=filter_type', 'acf_load_filter_type_field_choices');
    

    The Problem

    If I add just a select field to my custom post type page the “select” box populates dynamically and retains the value I set it to on every save.

    If I add the same “select” field inside a repeater it dynamically populates the field correctly, but it does not save the value for any amount of rows i create!

    Anyone have any ideas why a repeater sub-field that is dynamically assigned from an options page textarea is not saving the value for each row i add for the select field?

    Thanks.

  • This has since been resolved. It was due to incorrect targeting of a name attribute. For those having a similar issue just know this concept does work if you name everything correctly.

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

The topic ‘Dynamic select from options page doesn't save value in Repeater field’ is closed to new replies.