Support

Account

Home Forums General Issues ACF Resetting Data and Only Keeping Latest Row

Unread

ACF Resetting Data and Only Keeping Latest Row

  • Hi guys,

    I’m new to the forum but been messing around with ACF a while now.

    I’m building a site for a brewery, this brewery have requested an custom area.

    So, the idea is that they swap their ale with another brewery, and keep a record of what comes in and stock (allocated in).

    They also sell the allocated in stock to other pubs (allocated out).

    I’ve set up a CPT, with two seperate repeater fields and sub-fields.

    1. Allocated In (Repeater)
    – Brewery Name
    – Guest Beer
    – Stock Received

    2. Allocated Out
    – Stockist Name
    – Guest Beer
    – Stock Assigned
    – Stock Remaining

    You can view a working version: https://www.yeovilalesdev.com/stockists/may-2020/
    Password: yeovilales

    I’ve managed to get everything working, the only issue is too workout the ‘Stock Remaining’ in the ‘Allocated Out’ table, we need to do this:

    Stock In – Stock Out = Stock Remaining

    I have gotten this to work, but evwerytime I add a new Row, it removes the last Rows Data and leaves it blank…. Is there an issue with the reset post data?

    Code for the working page as shown above in the link (I have also attached a photo to better describe issue):

    All help greatly appreciated.

    <h3>Allocated In Report</h3>
    		<table>
    			<thead>
    				<tr>
    					<th>Brewery Name</th>
    					<th>Guest Beer</th>
    					<th>Stock Recieved</th>
    					<th>Date Ordered</th>
    					<th>Date Received</th>
    				</tr>
    			</thead>
    			<tbody>
    			<?php
    			// check if the repeater field has rows of data
    			if( have_rows('allocation_in') ):
    
    				// loop through the rows of data
    				while ( have_rows('allocation_in') ) : the_row(); 
    				$stockin = get_sub_field('stock_received');
    				global $post;
    				$guest = get_sub_field('guest_beer');
    				$guestURL = get_permalink($guest->ID);
    				$term = get_sub_field('brewery_name');
    				?>
    			
    					<tr>
    						<td><?php echo $term->name; ?></td>
    						<td><a href="<?php echo $guestURL; ?>"><?php echo $guest->post_title; ?></a></td>
    						<td><?php the_sub_field('stock_received');?></td>
    						<td><?php the_sub_field('date_ordered');?></td>
    						<td><?php the_sub_field('date_received');?></td>
    					</tr>
    
    				<?php endwhile; 
    
    			else :
    
    				echo '<h2>No Reports Found</h2>'; 
    
    			endif;
    
    			?>
    			</tbody>
    		</table>
    		<hr>
    				
    		<!--Allocated Out -->
    		<h3>Allocated Out Report</h3>
    		<table>
    			<thead>
    				<tr>
    					<th>Stockist Name</th>
    					<th>Guest Beer</th>
    					<th>Stock Assigned</th>
    					<th>Stock Remaining</th>
    					<th>Date Ordered</th>
    					<th>Date Received</th>
    				</tr>
    			</thead>
    			<tbody>
    			<?php
    			// check if the repeater field has rows of data
    			if( have_rows('allocation_out') ):
    
    				// loop through the rows of data
    				while ( have_rows('allocation_out') ) : the_row(); 
    				
    				global $post;
    				$stockout = get_sub_field('stock_assigned');
    				$stockremaining = ($stockin - $stockout);
    				$guest2 = get_sub_field('guest_beer_stockist');
    				$guestURL = get_permalink($guest2->ID);
    				$stockist = get_sub_field('stockist_name');
    				?>
    			
    					<tr>
    						<td><?php echo $stockist->name; ?></td>
    						<td><a href="<?php echo $guestURL; ?>"><?php echo $guest2->post_title; ?></a></td>
    						<td><?php the_sub_field('stock_assigned');?></td>
    						<td><?php if ( $guest2->ID == $guest->ID ) { echo $stockremaining; } else { 'No stock'; }?></td>
    						<td><?php the_sub_field('date_ordered_stockist');?></td>
    						<td><?php the_sub_field('date_received_stockist');?></td>
    					</tr>
    				
    				<?php 
    				
    				endwhile; 
    
    			else :
    
    				echo '<h2>No Reports Found</h2>'; 
    
    			endif;
    
    			?>
    			</tbody>
Viewing 1 post (of 1 total)

The topic ‘ACF Resetting Data and Only Keeping Latest Row’ is closed to new replies.