Home › Forums › Add-ons › Repeater Field › Repeater field shortcode? › Reply To: Repeater field shortcode?
Ok, I managed to deal with the code to output the repeater and subfields on the user’s profile page where the repeater fields are placed on the backend profile page of that user and make it in a nice table:
function acf_repeater() {
$user_id = get_current_user_id();
ob_start(); ?>
<?php if( have_rows('repeater-name',"user_{$user_id}" ) ): ?>
<table>
<tr>
<td>Header1:</td><td">Header2:</td><td>Header3:</td><td>Header4:</td>
</tr>
<?php while ( have_rows('repeater-name', "user_{$user_id}" ) ) : the_row();
// vars
$subfieldname1 = get_sub_field('sub-field-name-1');
$subfieldname2 = get_sub_field('sub-field-name-2');
$subfieldname3 = get_sub_field('sub-field-name-3');
$subfieldname4 = get_sub_field('sub-field-name-3');
?>
<tr>
<td><?php echo $subfieldname1; ?></td><td><?php echo $subfieldname2; ?></td><td><?php echo $subfieldname3; ?></td><td><?php echo $subfieldname4; ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
<?php $output = ob_get_clean();
return $output;
}
add_shortcode('acf_repeater_shortcode', 'acf_repeater');
I hope this will be usefull to someone…
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.