Support

Account

Home Forums Bug Reports After update string conversion error in ACF Pro Reply To: After update string conversion error in ACF Pro

  • Hi @jann

    Thanks for the bug report.
    I’ve found and fixed the issue!

    Would you mind testing out the patch? Please edit the api/api-template.php file and replace the have_rows function with this:

    
    /*
    *  have_rows
    *
    *  This function will instantiate a global variable containing the rows of a repeater or flexible content field,
    *  afterwhich, it will determine if another row exists to loop through
    *
    *  @type	function
    *  @date	2/09/13
    *  @since	4.3.0
    *
    *  @param	$field_name (string) the field name
    *  @param	$post_id (mixed) the post_id of which the value is saved against
    *  @return	(boolean)
    */
    
    function have_rows( $selector, $post_id = false ) {
    	
    	// reference
    	$_post_id = $post_id;
    	
    	
    	// filter post_id
    	$post_id = acf_get_valid_post_id( $post_id );
    	
    	
    	// vars
    	$key = "selector={$selector}/post_id={$post_id}";
    	$active_loop = acf_get_loop('active');
    	$previous_loop = acf_get_loop('previous');
    	$new_parent_loop = false;
    	$new_child_loop = false;
    	$sub_field = false;
    	$sub_exists = false;
    	$change = false;
    	
    	
    	// no active loops
    	if( !$active_loop ) {
    		
    		// create a new loop
    		$new_parent_loop = true;
    	
    	// loop has changed
    	} elseif( $active_loop['key'] != $key ) {
    		
    		// detect change
    		if( $post_id != $active_loop['post_id'] ) {
    			
    			$change = 'post_id';
    				
    		} elseif( $selector != $active_loop['selector'] ) {
    			
    			$change = 'selector';
    				
    		} else {
    			
    			// key has changed due to a technicallity, however, the post_id and selector are the same
    			
    		}
    		
    		
    		// attempt to find sub field
    		$sub_field = acf_get_sub_field($selector, $active_loop['field']);
    			
    		if( $sub_field ) {
    			
    			$sub_exists = isset( $active_loop['value'][ $active_loop['i'] ][ $sub_field['key'] ] );
    			
    		}
    		
    		
    		// If post_id has changed, this is most likely an archive loop
    		if( $change == 'post_id' ) {
    			
    			if( empty($_post_id) && $sub_exists ) {
    				
    				// case: Change in $post_id was due to this being a nested loop and not specifying the $post_id
    				// action: move down one level into a new loop
    				$new_child_loop = true;
    			
    			} elseif( $previous_loop && $previous_loop['post_id'] == $post_id ) {
    				
    				// case: Change in $post_id was due to a nested loop ending
    				// action: move up one level through the loops
    				acf_remove_loop('active');
    			
    			} else {
    				
    				// case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects
    				// action: leave this current loop alone and create a new parent loop
    				$new_parent_loop = true;
    				
    			}
    			
    		} elseif( $change == 'selector' ) {
    			
    			if( $previous_loop && $previous_loop['selector'] == $selector && $previous_loop['post_id'] == $post_id ) {
    				
    				// case: Change in $field_name was due to a nested loop ending
    				// action: move up one level through the loops
    				acf_remove_loop('active');
    				
    			} elseif( $sub_exists ) {
    				
    				// case: Change in $field_name was due to this being a nested loop
    				// action: move down one level into a new loop
    				$new_child_loop = true;
    				
    			} else {
    				
    				// case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post
    				// action: leave this current loop alone and create a new parent loop
    				$new_parent_loop = true;
    				
    			}
    			
    		}
    	
    	// loop is the same	
    	} else {
    		
    		// do nothing
    		
    	}
    	
    	
    	// add parent loop
    	if( $new_parent_loop ) {
    		
    		// vars
    		$field = get_field_object( $selector, $post_id, false );
    		$value = acf_extract_var( $field, 'value' );
    		
    		
    		// add loop
    		acf_add_loop(array(
    			'selector'	=> $selector,
    			'name'		=> $field['name'], // used by update_sub_field
    			'value'		=> $value,
    			'field'		=> $field,
    			'i'			=> -1,
    			'post_id'	=> $post_id,
    			'key'		=> $key
    		));
    	
    	// add child loop
    	} elseif( $new_child_loop ) {
    		
    		// vars
    		$value = $active_loop['value'][ $active_loop['i'] ][ $sub_field['key'] ];
    		$post_id = $active_loop['post_id'];
    		
    		
    		// add loop
    		acf_add_loop(array(
    			'selector'	=> $selector,
    			'name'		=> $active_loop['name'] . '_' . $active_loop['i'] . '_' . $sub_field['name'], // used by update_sub_field
    			'value'		=> $value,
    			'field'		=> $sub_field,
    			'i'			=> -1,
    			'post_id'	=> $post_id,
    			'key'		=> $key
    		));
    		
    	}	
    	
    	
    	// update vars
    	$active_loop = acf_get_loop('active');
    	
    	
    	// return true if next row exists
    	if( $active_loop && is_array($active_loop['value']) && isset($active_loop['value'][ $active_loop['i']+1 ]) ) {
    		
    		return true;
    		
    	}
    	
    	
    	// no next row!
    	acf_remove_loop('active');
    	
    	
    	// return
    	return false;
      
    }