Support

Account

Forum Replies Created

  • Well, sometimes the solution is just a few minutes away…sigh.

    To work around theme options regardless of language, we implemented How to get language independent ACF theme options on a WPML site

  • Hey John,

    Thanks again for another response!

    I’ve implemented the code and have found the following:

    1) when I create a new, clean product, with no value in the field where the multidimensional array is stored, I see the five rows in my form and the following error output:

    
    Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 26
    
    Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 27
    

    2) when i do create a field (via WooCommerce’s Booking plugin…the ‘_wc_booking_availability’ field, on the front-end ACF form, I see

    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Cannot use a scalar value as an array in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Cannot use a scalar value as an array in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'from' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 29
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    
    Warning: Illegal string offset 'to' in /Applications/MAMP/htdocs/acf/wp-content/themes/storefront/functions.php on line 30
    

    I really do appreciate your time in helping me with this so thanks again in advance. I don’t want to violate any kind of policy of ACF’s forum by soliciting services or whatnot, but would it be possible for me just to hire you to knock this out? I have the ability to create an environment and furnish access quickly.

    Thanks again!

  • 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!

  • Hi again,

    I created a ‘clean’ post to re-test this and am posting what i found in hopes that it helps a bit. I found that the array being output from ACF is:

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

    the value from the pre-existing field straight from WordPress is

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

    Thanks again!

  • Hi John,

    Thanks for the super-quick response. I’ve removed those filters from the page template and placed the code that you’ve provided in my functions.php.

    This however, triggered some errors:

    
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Cannot use a scalar value as an array in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Cannot use a scalar value as an array in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'from' in ~/wp-content/themes/storefront/functions.php on line 32
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    Warning: Illegal string offset 'to' in ~/wp-content/themes/storefront/functions.php on line 33
    
    

    I’m going to start investigating these myself, but thought I’d send you this along already if you know why this is happening.

    Thanks in advance!

  • Hi John,

    Thanks for the response!

    I’ve been fiddling with the code that you sent. The good news is with your code, I’m able to get empty rows to show in the repeater field. The not-so-good news is I’m still not able to pre-populate the form rows with values on the front end, nor post the values to the correct pre-existing field.

    I’ve noticed that the pre-existing field (‘availability’ field, we’re using WooCommerce Bookings) is wrapping the item in an extra array, such as:

    
    Array ( [0] => Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 2016-02-02 [to] => 2016-02-03 ) [1] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-10 [to] => 2016-02-12 ) [2] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-04 [to] => 2016-02-20 ) ) ) 
    

    …whereas, the array output from ACF using your code is:

    
    Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 2016-02-02 [to] => 2016-02-03 ) [1] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-10 [to] => 2016-02-12 ) [2] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-04 [to] => 2016-02-20 ) ) 
    

    The code I’m using so far:

    
    <?php
    /**
     * The template for displaying full width pages.
     *
     * Template Name: ACF Front End Repeater Form
     *
     * @package storefront
     */
    ?>
    <?php $post_id = 55; ?>
    <?php acf_form_head(); ?>
    <?php get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    		<?php
    			
    		add_filter('acf/load_value/name=my_repeater_field','load_my_repeater_field_value', 10, 3);
    		
    		function  load_my_repeater_field_value($value, $post_id, $field) {
    			/* 
    				--> adding the array() around get_post_meta() makes this output array match the default one (see line 57 below please), but it does not render form rows
    				
    				$load_value =  maybe_unserialize(get_post_meta($post_id, '_wc_booking_availability', true)); 
    			*/
    			$load_value =  maybe_unserialize(get_post_meta($post_id, '_wc_booking_availability', true));
    			return $load_value;
    			/* 
    				--> tried this, but it added extra empty rows somehow
    
    				return call_user_func_array('array_merge', $load_value);
    			*/
    		};
    		
    		?>
    			
    			<?php
    				$options = array(
    					'post_id' => $post_id,
    					'post_title' => true,
    					'field_groups' => array(
    						18,
    					),
    					'submit_value' => __("Update", 'acf'),
    					'updated_message' => __("Post updated", 'acf'),
    					'uploader' => 'wp'
    				);
    			?>
    			<?php acf_form($options); ?>
    			<?php 
    			add_filter('acf/save_post', 'update_my_repeater_field_value', 20);
    			function update_my_repeater_field_value($post_id) {
    				// check the post type
    				// you don't want to do this on every post type
    				if (get_post_type($post_id) != 'product') {
    					return;
    				}
    				$value = get_field('my_repeater_field', $post_id);
    				update_post_meta($post_id, '_wc_booking_availability', $value);
    			} // when i submit the field, the ACF array (output below) deletes all the values
    			?>
    			
    			<?php
    				// Printing both the pre-existing field and the ACF field arrays for debugging/testing
    				
    				// 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));
    					echo '<br><br><hr>';
    					echo 'Pre-existing field array (when I \'flatten\' the pre-existing array):<br><br>';
    					$flat = call_user_func_array('array_merge', $pre_existing_array);
    					print_r(array_values($flat)); // this DOES match the array for the pre-existing field 
    					echo '<br><br><hr>';
    				};
    			?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>
    
    

    I’m at the point where I don’t know if I’m making progress or just getting more lost, so huge, huge thanks in advance for any insights!

Viewing 6 posts - 1 through 6 (of 6 total)