php – Update user repeater meta (ACF) with another user meta field value

Question

My goal is to get a signed-in user to select a color (saved in ACF user meta field group) that will be applied to another user meta field inside a repeater. the field must be the same for each row inside the repeater ( for front-end design reasons ). I am using ACF pro, and a plugin called ACF Front end admin (lets call it FEA from now on) for the front end form. I’m pretty new to PHP and have referenced ACF & FEA’s s documentation, which can be found below, to spin up a custom function. I am currently running this through code snippets plugin if this helps.

I’m running the following code with no luck and would really appreciate any help!


    /// Hooks into any(?) form and does something
add_action('acf_frontend/save_user', 'retrieve_colors_2_update', 10, 2);
function retrieve_colors_2_update( $form, $user_id ) {
    $user = get_user_by('ID',$user_id);
    //get important fields
    $btn_color = get_field('button_color', 'user_' .$user_id);
    //// update a repeater loop (ACF)
    if( have_rows('quick_link_selector', 'user_'.$user_id) ) {
        $i = 0;
        while( have_rows('quick_link_selector') ) {
            the_row();
            $i++;
            update_sub_field('repeater_button_color', $btn_color );
    }
}
}

0
Luca 1 month 2022-08-20T20:16:44-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse