Support

Account

Home Forums Add-ons Repeater Field Taking Repeater fields and setting them as default entries for another repeater

Helping

Taking Repeater fields and setting them as default entries for another repeater

  • Hi, I know there are threads out there around a similar issue, but I have tried for a few days to get this to work and I’m just stumped. Can you tell me where I’m going wrong. I’m setting up some custom fields for a user to set their default values for use in other places in our site. So they go in and select and enter details that are then automatically put into other fields when a new post is created. And I have the filters working on normal fields, but the repeater field has got me stumped. Here is the code I’m using to make my normal fields work:

    function my_acf_load_project_frame_rate( $field ) {
    global $current_user;
    wp_get_current_user();
    $user_id = “user_” . $current_user->ID;

    $frame_rate = get_field(‘default_frame_rate’, $user_id);

    $field[‘default_value’] = $frame_rate;
    return $field;
    }

    add_filter(‘acf/load_field/key=field_57a875a7845a0’, ‘my_acf_load_project_frame_rate’);

    This code works great for a regular text field. And here is what I’m trying to do with a repeater field. My documentation inside the code explaining each piece as I see it. I did tests trying to put value into a text field and it’s clear I’m not getting the data from the default fields first… and then I’m sure I need another solution to put that data into the destination field..

    Thank you so much for anything you can offer.

    /load default value for checklists
    function my_acf_load_project_cl( $field ) {
    global $current_user;
    wp_get_current_user();
    $user_id = “user_” . $current_user->ID;
    // I’m assuming the code below loads the value of the field called “default_checklist”. this // is a repeater field, and this is the parent level
    $cl = get_field(‘default_checklist’, $user_id);
    // I’m trying to use an array to go in and get the values of the parent field… if it has //rows than get the values in the repeater fields?.
    $cl_items = array();
    if ( have_rows(‘default_checklist’, $post) ) :
    while ( have_rows(‘default_checklist’, $post) ) : the_row();
    $cl_SubItems[] = array (get_sub_field(‘default_item_text’),get_sub_field(‘default_correct_response’) );
    endwhile;
    endif;

    $field[‘default_value’] = $cl_items;
    return $field;
    }

    add_filter(‘acf/load_field/key=field_57a875a7845a0’, ‘my_acf_load_project_cl’);

    ——
    So again, I want to take the values in a repeater field, and then add_filter for another repeater field to load those default values into the repeater fields… and then the user can add more if they want… does that make sense.

    Thanks again for any guidance.

    Steve

  • This question is hard to read without using the ‘code’ tags. Can you add these to any text in this post that you want to be read as code?

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

The topic ‘Taking Repeater fields and setting them as default entries for another repeater’ is closed to new replies.