• Resolved samjco

    (@samjco)


    I am using option pages to show my repeatable fields.
    I have an enhanced message field as a sub field in my repeatable field
    I am using the following code:

    add_action('acf/render_field/name=enhancedfield', 'acf_enhancedfield');
    function acf_enhancedfield(){
    
    $rows = get_field('repeater_field_name');
    $row_count = count($rows); //Total count of repeatable fields
    $i = 0 //Target First repeatable array
    
    echo $rows[ $i ]['sub_field_name']; //content to show in Enhanced Field of just the first...
    }

    Now the issue is, the content renders within the second repeatable field as well.
    How can I have it to just show in its respected enhanced fields within its repeatable fields?

    • This topic was modified 4 years ago by samjco.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! This question is about general ACF development and not ACF Extended itself tho. In the ACF logic, fields are kind of isolated from each others, this is what makes ACF such a flexible tool.

    If you want to retrieve the current repeater row number in an Advanced Message field, you’ll have to set & update a counter. Here is a code example:

    // Render Message
    add_action('acf/render_field/name=my_message', 'my_acf_render_message');
    function my_acf_render_message($field){
        
        global $i;
        
        $i = isset($i) ? $i : 0;
        $i++;
        
        echo 'Row: ' . $i;
        
    }
    

    Regards.

    Thread Starter samjco

    (@samjco)

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Enhanced Message Field – How to target field within repeatable field’ is closed to new replies.