Home › Forums › Add-ons › Repeater Field › Simple update for repeater subfield › Reply To: Simple update for repeater subfield
Ok, so the finished code goes like this:
$guilds = get_field('guilds','options');
$g_counter = 0;
foreach($guilds as $guild){
$members = get_users('meta_key=u_guild&meta_value='.$guild['guild_id']);
$guildXP = 0;
foreach($members as $member){
$guildXP += $member->u_xp;
}
$field_key = "guilds";
$post_id = "options";
$value = get_field($field_key, $post_id);
$guild['guild_xp'] = $guildXP;
$value[$g_counter] = $guild;
update_field( $field_key, $value, $post_id );
$g_counter++;
?>
<tr>
<td><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $guild['guild_id']; ?>.png"></td>
<td class="guild-name"><?php echo $guild['guild_name']; ?></td>
<td class="skill-name"><?php echo $guild['guild_skill']; ?></td>
<td class="guild-xp"><?php echo $guild['guild_xp']; ?></td>
<td class="guild-members"><?php echo count($members); ?></td>
</tr>
<?php } ?>
I had to rewrite each row from the field and update the whole field every loop…
And the trick is to use 2 variables for the same field… At least this is how I solved it 😀 if anyone has comments I’m open!
Thanks for the tip Elliot 😀
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.