Support

Account

Home Forums Backend Issues (wp-admin) Issue with acf/fields/flexible_content/layout_title & repeater fields Reply To: Issue with acf/fields/flexible_content/layout_title & repeater fields

  • Hi @newjenk

    It seems you need to handle the AJAX with a special code. The AJAX posts the data using the field key, so you need to do use it in the code. Here’s an example how to do that:

    function my_acf_flexible_content_layout_title_ajax( $title, $field, $layout, $i ) {
    	
        if( $layout['name'] != 'module_list' ) return $title;
        
    	$title = '';
        
        // code to handle the AJAX
        if( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ){
            
            // get the posted (new) repeater data
            // field_583ae9699490e: the flexible content field key
            // field_583de95713b2d: the repeater field key
            $new_repeater_data = $_POST['acf']['field_583ae9699490e'][$i]['field_583de95713b2d'];
            
            // loop through the repeater data
            foreach( $new_repeater_data as $row ){
                
                // field_583dea8513b2f: bold_text_title field key
                $title .= '<h3>' . $row['field_583dea8513b2f'] . '</h3>';
                
                // field_583deab013b30: smaller_text field key
    			$title .= '<p>' . $row['field_583deab013b30'] . '</p>';
                
            }
            
        } elseif ( have_rows('module_list_items') ){
    
    		while( have_rows('module_list_items') ) : the_row();
            
    			$title .= '<h3>' . $boldText = get_sub_field('bold_text_title') . '</h3>';
    			$title .= '<p>' . $smallText = get_sub_field('smaller_text') . '</p>';
    
    		endwhile;
    
        }
    	
    	return $title;
    
    }
    add_filter('acf/fields/flexible_content/layout_title/name=page_modules', 'my_acf_flexible_content_layout_title_ajax', 10, 4);

    I hope this helps 🙂