Support

Account

Home Forums Front-end Issues Custom fields in repeater users Reply To: Custom fields in repeater users

  • Hi Elliot,
    The extra fields are to extend the WP standard user. After doing a remake of a large local government site a few years ago I like to try and keep all ‘people’ in one place.
    After a bit of mucking around I got that to work. For the benefit of anyone else doing this here’s the code.

    <?php if(get_field('people')): ?>
    	<?php while(has_sub_field('people')): ?>
    		<ul class="person">
    			<?php $person=get_sub_field('person'); ?>
    			<?php $person_id=$person['ID']; 
    				$cell = get_field('cell', "user_{$person_id}"); 
    				$phone = get_field('phone', "user_{$person_id}"); 
    				$firstname=$person['user_firstname'];
    				$lastname=$person['user_lastname'];
    				$email=$person['user_email'];
    				$userid=get_field('user_{$person_id');
    				echo $personid;
    			?>
    			<li> <?php echo get_avatar( $email, $size, $default, $alt ); ?> </li>
    			<li class="persondetails">
    				<?php echo $firstname; ?> 
    				<?php echo $lastname; ?> 
    				<?php echo $email; ?> 
    				<?php if ($cell != '0'){ ?>Cell: 0<?php echo $cell; ?><?php } else {} ?> 
    				<?php if ($phone != '0'){ ?>Phone: <?php echo $phone; ?><?php } else {} ?> 
    				<?php the_sub_field('person=>user_lastname'); ?>
    				 <a href="<?php echo get_edit_user_link($person_id); ?>">edit person</a>
    			</li>
    
    		</ul>
    	<?php endwhile; ?>
    <?php endif; ?>

    The number fields seem to strip leading zeros and default to zero. Not sure if there’s a more sensible way of dealing with phone numbers, but this seems to work ok for me.
    I wasn’t sure about using ‘user’ as a field name. It’s not a reserved word, but having multiple ‘user’ labels can make things pretty confusing.