Support

Account

Home Forums ACF PRO Get last row from a flexible content and display it on another page Reply To: Get last row from a flexible content and display it on another page

  • Hi, thanks for your help ๐Ÿ™‚
    So I did that, but doesn’t seem to work yet.

    
    		  	<?php
    
    			$post_object = array_reverse(get_field('relation'));
    			$post_object[0]
    			
    			$repeater = get_field('repeater', $post_object->id);
    					$last_row = end($repeater);
    					$last_row['subhead'];
    
    			if( $post_object ): 
    
    			// override $post
    			$post = $post_object;
    			setup_postdata( $post ); 		
    
    			?>
    		    <div>
    		    	
                        	
    					<?php
    
    					
    
    					// check if the flexible content field has rows of data
    					if( have_rows('selection') ):
    					// loop through the rows of data
    					while ( have_rows('selection') ) : the_row();
    					if( get_row_layout() == 'selectionselection' ):?>
    
    						<div class="titre-soustitre">
    						    <div class="menu-content" data-id="id-<?php echo $post_object[0]['id']; ?>">
    						        <p class="demo bis"><span class="sub">&nbsp;</span></p>
    						        <a href="#" class="expander"><h1><p class="demo title"><?php echo $post_object[0]['title'] ?></p></h1></a>              
    						        <p class="demo bis"><span class="sub"><?php echo $post_object[0]['subhead']; ?></span></p>
    						    </div>
    						</div>
    						            
    
    				
    
    					<?php endif;
    					endwhile;
    					else :
    					// no layouts found
    					endif;
    
    					?>
    
    		    </div>
    		    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    			<?php endif; ?>

    I guess I should define the ID on the original flexible content ?
    So far, the ID I use on the original flexible content are written by hand through a text field like this data-id="id-<?php the_sub_field('id');?>
    Should I change that ?