Support

Account

Home Forums ACF PRO Updating sub field doesn't work

Unread

Updating sub field doesn't work

  • I’m trying to update a true/false field (session_is_live) within a repeater. What I am doing wrong? Do I still miss something? The conditional around the update_sub_field() is working.

    
    			<?php while ( have_rows( 'sessions' ) ) : ?>
    				<?php the_row(); ?>
    				<?php
    				$session_type            = get_sub_field( 'session_or_break' );
    				$session_time_from_orig  = get_sub_field( 'session_speaker_time_from' );
    				$session_time_from       = date( 'H:i', strtotime( $session_time_from_orig ) );
    				$session_time_until_orig = get_sub_field( 'session_speaker_time_until' );
    				$session_time_until      = date( 'H:i', strtotime( $session_time_until_orig ) );
    				$session_topic           = get_sub_field( 'session_speaker_topic' );
    				$session_speaker         = get_sub_field( 'session_speaker_speaker' );
    				$session_is_live         = get_sub_field( 'session_is_live' );
    
    				$session_time_from_orig  = get_sub_field( 'session_speaker_time_from' );
    				$session_time_until_orig = get_sub_field( 'session_speaker_time_until' );
    				$current_date_time       = date( 'Y-m-d H:i', strtotime( '+2 hours' ) );
    
    				if ( $current_date_time >= $session_time_from_orig && $current_date_time <= $session_time_until_orig ) {
    					update_sub_field( 'session_is_live', 1, get_the_ID() );
    					echo 'is live';
    				} else {
    					update_sub_field( 'session_is_live', 0, get_the_ID() );
    				}
    				?>
    				<?php if ( $session_type == 'break' ) : ?>
                        <div class="sessions__session">
                            <div class="sessions__head sessions__head--pause">
                                <div class="sessions__topic"><?php _e( 'Break', 'uxcamp-on' ); ?></div>
                            </div>
                        </div>
    				<?php elseif ( $session_type == 'session' ) : ?>
                        <div class="sessions__session<?php if ( $session_is_live ) : ?> active<?php endif; ?>">
                            <div id="heading-<?php echo $counter; ?>">
                                <button class="sessions__head" type="button" data-toggle="collapse" data-target="#collapse-<?php echo $counter; ?>" aria-expanded="<?php if ( $session_is_live ) : ?>true<?php else : ?>false<?php endif; ?>" aria-controls="collapse-<?php echo $counter; ?>">
                                    <div class="sessions__time"><?php the_svgicon( 'chevron-right-regular' ); ?><?php echo $session_time_from; ?> - <?php echo $session_time_until; ?></div>
                                    <div class="sessions__topic">
    	                                <?php if ( $session_is_live ) : ?>
                                        <span class="sessions__is-live">
                                            <span class="sessions__is-live-dot"></span>
                                            <span class="sessions__is-live-ring"></span>
                                            <span class="sessions__is-live-text">Live</span>
                                        </span>
                                        <?php endif; ?>
                                        <span class="sessions__topic-text">
                                            <?php echo $session_topic; ?>
                                        </span>
                                    </div>
                                    <div class="sessions__speaker"><span class="sessions__speaker-text"><?php echo $session_speaker; ?></span></div>
                                    <div class="sessions__collapse"><?php the_svgicon( 'chevron-up-regular' ); ?></div>
                                </button>
                            </div>
                            <div id="collapse-<?php echo $counter; ?>" class="sessions__content<?php if ( $session_is_live ) : ?> show<?php endif; ?>" aria-labelledby="heading-<?php echo $counter; ?>" data-parent="#sessions-list">
                                <div class="sessions__body">
                                    <div class="sessions__left">
                                        <img src="https://source.unsplash.com/5aGUyCW_PJw/200x200" alt="">
                                    </div>
                                    <div class="sessions__right">
                                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch.
                                    </div>
                                </div>
                            </div>
                        </div>
    				<?php endif; ?>
                    <?php $counter++; ?>
    			<?php endwhile; ?>
    
Viewing 1 post (of 1 total)

The topic ‘Updating sub field doesn't work’ is closed to new replies.