- Create you acf repeater field and make sure to copy field Name and sub field Name.
- Go to the wp code and add this snippet provided last. Please don't forget to change the field name and sub field name that is added in snippets below.
- Then add the shortcode in elementor where you want to place those
3 Versions provided. This colour represents a shortcode to be used on Elementor. Use that in [Code ] like this
FULL CODE:
/* WITH BULLETS
shortcode for displaying required posting repeater field from ACF*/
add_shortcode ('show-required', 'dnlt_show_required');
function dnlt_show_required() {
$pageID = get_the_ID(); // not required if within loop, but doesn't hurt
$content= '';
if( have_rows('subjects_studied', $pageID) ) {
$content .= '<ul>';
while( have_rows('subjects_studied', $pageID) ) {
the_row();
$content .= '<li>' . get_sub_field('subjects') . '</li>';
}
$content .= '</ul>';
}
return $content;
}
/* WITH NO BULLETS
shortcode for displaying required posting repeater field from ACF*/
add_shortcode('show-required', 'dnlt_show_required');
function dnlt_show_required() {
$pageID = get_the_ID(); // not required if within loop, but doesn't hurt
$content = '';
if (have_rows('subjects_studied', $pageID)) {
while (have_rows('subjects_studied', $pageID)) {
the_row();
$content .= get_sub_field('subjects') . '<br>'; // Use <br> for line breaks
}
}
return $content;
}
/* WITH COMMAS AND NO BULLETS
shortcode for displaying required posting repeater field from ACF */
add_shortcode('show-required', 'dnlt_show_required');
function dnlt_show_required() {
$pageID = get_the_ID(); // not required if within loop, but doesn't hurt
$content = '';
$subjects = array(); // Create an array to store subjects
if (have_rows('subjects_studied', $pageID)) {
while (have_rows('subjects_studied', $pageID)) {
the_row();
$subjects[] = get_sub_field('subjects'); // Add each subject to the array
}
}
// Use implode to join subjects with commas and create the content
$content = implode(', ', $subjects);
return $content;
}
Reference Video:
Hurrah – Done
