Support

Account

Home Forums Add-ons Repeater Field using update_field on a repeater in options page

Solved

using update_field on a repeater in options page

  • I want to set defaults in a repeater on an options page. Is this possible?

    http://www.advancedcustomfields.com/resources/functions/update_field/ This page has some examples of using update_field and I imagine they work with normal fields on an options page, but considering get_field(‘my_repeater’,’options’) returns a number instead of rows I don’t know how to pull this off.

    This is how I would expect it to work:

    
    update_option('acf-options-set-default', 1); // set on wp install
    
    if( get_option('acf-options-set-default') ) {
    	update_option('acf-options-set-default', 0);
    	$defaults=get_default_external_links();
    	foreach($defaults as $link) {
    		$linkName=$link['link_name'];
    		$linkURL=$link['link_url'];
    		$linkModal=$link['link_modal'];
    		$value = get_field('repeater_parent_links', 'option');
    		value[] = array(
    			'link_name' => $linkName, 
    			'link_url' => $linkURL,
    			'link_modal' => $linkModal
    		);
    		update_field( 'repeater_parent_links', $value, 'option' );
    	}	
    }
  • Hi @dverleger

    Currently, any functions loading or saving data to the repeater field must be run AFTER the init action.

    It is most likely that you code is within the root of the funtions.php file, and needs to be moved inside a function connected to the init action.

    Hope that helps

    Thanks
    E

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

The topic ‘using update_field on a repeater in options page’ is closed to new replies.