Home › Forums › Add-ons › Repeater Field › ACF Repeater Loop Doesn't work
I have an Advanced Custom Fields repeater loop that was able to get information on a ticket from a specific ACF field from a specific user. Everytime i put this in a different page, the code works fine, but when i use it in another area, nothing happens and nothing shows up.
i used this as my guide: https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/
I have latest ACF pro installed. I have provided the code that is both in the shortcode and also that is in template file and screenshots.
/****the cars shortcode*****/
function addcars() {
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$currentuser_ID = 'user_'.$userID; ?>
<form>
<select>
<option>Select A Car</option>
<?php if( have_rows('my_cars', $currentuser_ID) ): ?>
<?php while( have_rows('my_cars', $currentuser_ID) ): the_row(); ?>
<option value="<?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('color'); ?> <?php echo the_sub_field('license_plate'); ?>"><?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('color'); ?> <?php echo the_sub_field('license_plate'); ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</form>
<?php
}
add_shortcode( 'thecars', 'addcars' );
/****Template File for tickets*****/
<?php
/**
* The template for the select input
*
* Override this template in your own theme by creating a file at:
* [your-theme]/tribe/tickets/registration/attendees/fields/select.php
*
* @since 4.9
* @since 4.10.1 Update template paths to add the "registration/" prefix
* @version 4.10.1
*
*/
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$userRole = $current_user->role;
$currentuser_ID = 'user_'.$userID;
$required = isset( $field->required ) && 'on' === $field->required ? true : false;
$field = (array) $field;
$attendee_id = $key;
$is_restricted = false;
$slug = $field['slug'];
$options = null;
$field_name = 'tribe-tickets-meta[' . $ticket->ID . '][' . $attendee_id . '][' . esc_attr( $field['slug'] ) . ']';
if ( isset( $field['extra'] ) && ! empty( $field['extra']['options'] ) ) {
$options = $field['extra']['options'];
}
if ( ! $options ) {
return;
}
$option_id = "tribe-tickets-meta_{$slug}_{$ticket->ID}" . ( $attendee_id ? '_' . $attendee_id : '' );
?>
<div class="tribe-field tribe-block__tickets__item__attendee__field__select <?php echo $required ? 'tribe-tickets-meta-required' : ''; ?>">
<label for="<?php echo esc_attr( $option_id ); ?>"><?php echo wp_kses_post( $field['label'] ); ?></label>
<select
<?php disabled( $is_restricted ); ?>
id="<?php echo esc_attr( $option_id ); ?>"
class="ticket-meta"
name="<?php echo esc_attr( $field_name ); ?>"
<?php echo $required ? 'required' : ''; ?>>
<!----Start of ACF Repeater Loop---->
<option>Select a car</option>
<?php if( have_rows('my_cars', $currentuser_ID) ): ?>
<?php while( have_rows('my_cars', $currentuser_ID) ): the_row(); ?>
<option value="<?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('year'); ?>"><?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('year'); ?> <?php echo the_sub_field('color'); ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
The topic ‘ACF Repeater Loop Doesn't work’ is closed to new replies.
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.