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 );
    		<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>
    <?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 😀