Support

Account

Home Forums Add-ons Repeater Field Adding repeater field with update_post_meta

Solved

Adding repeater field with update_post_meta

  • Hello i am developing a website and have order process where people can add products with different fields describing them.
    After they submit the order i create a post with a custom post type “orders”.
    then i have a repeater field where called “product_info”
    so while running the order process i create custom fields in this manner.

    $product_number = 0; 
    								
    	foreach($product_info as $product_info_each) {
    	
    		foreach($product_info_each as $key=>$value) { 
    			
    			update_post_meta($post_id, 'product_info_'.$product_number.'_'.$key, $value);
    			
    		}	
    		
    		$product_number++;		
    				
    	}
    	
    	update_post_meta($post_id, 'product_info', count($product_info));

    So when i open the order i can see all the info sitting there nicely in the repeater field.
    but when i try to display the product info on the customers My Account page
    the get_field(‘product_info’) return just the array count value. But after i save the Order in the editing page it then return proper array.
    so as i see when i same the Order in the editing screen it adds all kinds of new meta to the post like ‘ [_product_info_2_product_color] => Array ( [0] => field_522202dc8c2c4 ) ‘ and after than the repeater field returns the correct value. is there a way i can run some hook or filter for the repeater field to return proper arrays.

    Thanks!
    love your plugin!

  • Hi @karbanovich

    All you need to do is ditch the current code which uses the native post meta functions, and use the ACF update_field function.

    This function will expect a multi-dimentional array as the value (an array of rows each containing the cell)

    Don’t save each sub field separately, but only save the repeater field once with all the data!

    Let me know if you run into any issues.
    http://www.advancedcustomfields.com/resources/functions/update_field/

    Thanks
    E

  • Hey man!
    thanks for that help.
    works a magic! i gues need to dig into the documentation better!

    you are the man!

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

The topic ‘Adding repeater field with update_post_meta’ is closed to new replies.