Support

Account

Home Forums Add-ons Repeater Field Repeater field is not updating data with programmatically added pages

Solved

Repeater field is not updating data with programmatically added pages

  • When we add new page to the WordPress using “wp_insert_post” and insert data to the repeater field on this page using acf update_field function the data is not visible in backend page edit screen.

    We are using basic repeater field:
    Field name is “features” and it has sub fields “name” and “value”.

    	$newPage = array(
    		'post_title' => $pageTitle,
    		'post_name' => $pageName,
    		'post_type' => 'page',
    		'post_status' =>'publish',
    		'post_parent' => $parent,
    	);
    	$pageID = wp_insert_post($newPage);
    	$value = array(
    		array(
    			"name"	=> "name1",
    			"value"	=> 'value1',
    		),
    		array(
    			"name"	=> "name2",
    			"value"	=> 'value2',
    		),
    	);
    	update_field( 'features', $value, $pageID );
    
    

    After we run the code, page is created but the ‘features’ fields are empty when accessed through backend, although they are set in database (get_field function in front end returns them).

    One more notice is that, if we’d created the page using wp_post_insert, then manually published it through backend (publish button) then update_field function works.

    How can we fix this, since we have an import of hundreds pages. and manually updating is impossible.

  • When updating ACF fields where they do not already exist, for a new post, you must use the field keys to do the updating. See the Advanced section on this page https://www.advancedcustomfields.com/resources/update_field/

  • I have same issue, it must use the field key to update

  • @onion is that a question or a statement?

    When updating ACF fields for a new post where there is no previous values set for those fields, you must use the field key for the field when calling update_field().

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

The topic ‘Repeater field is not updating data with programmatically added pages’ is closed to new replies.