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!
ACF wouldnât be so widely used in WordPress if it didnât have some pretty amazing capabilities. In this article, we look at a few of the features weâll discuss during â7 things you didnât know you could do with ACFâ at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.