Support

Account

Home Forums Add-ons Repeater Field Using acf_form() to store/fetch a multidimensional array meta_key Reply To: Using acf_form() to store/fetch a multidimensional array meta_key

  • Hi John,

    Thanks again for another response!

    I’ve implemented the code that you sent and see that:

    1) the ACF form is still loading the row, but the values are empty
    2) when i click the ‘update button on the ACF form, I get the following error

    
    Warning: Cannot modify header information - headers already sent by (output started at ~/wp-content/themes/storefront/template-acf.php:12) in ~/wp-includes/pluggable.php on line 1228
    

    In my page template, I’ve the following code to see what’s going on with the arrays:

    
    
    			<?php
    				// Printing both the pre-existing field and the ACF field arrays for debugging/testing
    				
    				// ACF
    				echo 'ACF repeater field array from load value filter:<br><br>';
    				if( empty( $load_value ) ){
    					echo '<strong>Empty</strong><br><br>';
    				} else {
    					print_r(array_values($load_value)); // this doesn't match the array for the pre-existing field unless i wrap get_post_meta() in an array() on line 25
    					echo '<br><br><hr>';
    				};
    
    				// ACF
    				$acf_repeater_array = get_field( "my_repeater_field", $post_id);
    				echo 'ACF repeater field array:<br><br>';
    				if( empty( $acf_repeater_array ) ){
    					echo '<strong>Empty</strong><br><br>';
    				} else {
    					print_r(array_values($acf_repeater_array)); // this doesn't match the array for the pre-existing field unless i wrap get_post_meta() in an array() on line 25
    					echo '<br><br><hr>';
    				};
    			
    				// Pre-existing field
    				$pre_existing_array = get_post_meta( $post_id, '_wc_booking_availability' );
    				echo  'Pre-existing field array:<br><br>';
    				if( empty( $pre_existing_array ) ){
    					echo '<strong>Empty</strong><br><br>';
    				} else {
    					print_r(array_values($pre_existing_array));
    				};
    			?>
    
    

    ACF repeater field array from load value filter:

    
    Empty
    

    ACF repeater field array:

    
    Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 20160211 [to] => 20160219 ) )
    

    Pre-existing field array:

    
    Array ( [0] => Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 2016-02-11 [to] => 2016-02-19 ) ) ) 
    

    In case this helps, the value pasted directly from phpMyadmin for the pre-existing array field (_wc_booking_availability) is:

    
    
    a:1:{i:0;a:5:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:8:"priority";i:10;s:4:"from";s:10:"2016-02-11";s:2:"to";s:10:"2016-02-19";}}
    
    

    I really appreciate your effort and time with helping me on this, so thanks again in advance!