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
I’m sorry I missed that. It seems the new layout has a different data structure. You can check it by using the network tab of your developer tools (Google Chrome).
Here’s an example how to handle the new layout too:
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 ){
// set the keys for repeated usage
// field_583ae9699490e: the flexible content field key
// field_583de95713b2d: the repeater field key
$flexible_key = 'field_583ae9699490e';
$repeater_key = 'field_583de95713b2d';
// get the flexible content data
$flexible_data = $_POST['acf'][$flexible_key];
// loop through the flexible content data
foreach( $flexible_data as $flexible_row ){
// check if the repeater is set
if( isset($flexible_row[$repeater_key]) && !empty($flexible_row[$repeater_key]) ){
$repeater_data = $flexible_row[$repeater_key];
// loop through the repeater data
foreach( $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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.