Home › Forums › Add-ons › Repeater Field › Having issues with ACF Repeater fields on a multisite › Reply To: Having issues with ACF Repeater fields on a multisite
It’s not specifically for generatepress; this is the code:
function my_acf_repeater($atts, $content='') {
extract(shortcode_atts(array(
"field" => null,
"sub_fields" => null,
"post_id" => null
), $atts));
if (empty($field) || empty($sub_fields)) {
// silently fail? is that the best option? idk
return "";
}
$sub_fields = explode(",", $sub_fields);
$_finalContent = '';
if( have_rows($field, option) ):
while ( have_rows($field, option) ) : the_row();
$_tmp = $content;
foreach ($sub_fields as $sub) {
$subValue = get_sub_field(trim($sub));
$_tmp = str_replace("%$sub%", $subValue, $_tmp);
}
$_finalContent .= do_shortcode( $_tmp );
endwhile;
else :
$_finalContent = "<center><h2>There is nothing to see here right now!</h2><br><p>Please check back soon</p></center>";
endif;
return $_finalContent;
}
add_shortcode("acf_repeater", "my_acf_repeater");
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.