Support

Account

Home Forums Add-ons Repeater Field ACF 5.0+ Dynamically Populating Repeater Reply To: ACF 5.0+ Dynamically Populating Repeater

  • I was running ACF PRO 5.7.0 but as an mu-plugin so it wasn’t obvious to me there was newer versions.

    Elliot replied in a ticket to me;

    In the most recent versions of ACF and ACF PRO we have moved around the order of actions allowing the “acf/load_value” action to run last (after “acf/load_value/type=repeater”).

    If you hook into the “acf/load_value” filter, you should now be able to customize the repeater field value as an array, not as a numeric number.

    So this has changed very recently. Now with version 5.7.6 you can handle it like this;

    	function my_acf_load_method($value, $post_id, $field) {
    			
    		if ($field['type'] == 'number') {
    
    			$value = 123;			
    
    			return $value;
    
    		} elseif ($field['type'] == 'repeater') {	
    		
    			$value[] = array(
    				'field_url' => 'http://www.google.com',
    				'field_text' => 'Google'
    			);
    
    			return $value;
    			
    		}	
    		
    	}
    	
    	add_filter('acf/load_value', 'my_acf_load_method', 20, 3);
    

    Checking the value of your repeater, returning $value as a string where the acf/load_value method is expecting a string, and $value as an array when it’s expecting an array.

    Much easier, thanks again Howdie_McGee.