Support

Account

Home Forums General Issues Prepopulate repeater fields? Reply To: Prepopulate repeater fields?

  • Whoops. I was missing that part — thank you.

    I got it to work as a repeater on posts, but when it’s a repeater inside a block it doesn’t. Maybe I need to add in the block key too? (The top key is the repeater and the key inside the array is the sub_field.)

    // Add field key of the repeater
    add_filter('acf/load_value/key=key=field_5cf9732cb05a', 'afc_load_my_repeater_value', 10, 3);
    
    function afc_load_my_repeater_value($value, $post_id, $field) {
    
    			 //Optional: Check for post_status otherwise published values will be changed.
    	 if ( get_post_status( $post_id ) === 'auto-draft' ) {
    
    			 $value	= array();
    
    			// Add field key for the field you would to put a default value
    			 $value[] = array(
    				 'field_5cf979117a655' => 'Label 1'
    			 );
    			 $value[] = array(
    				 'field_5cf979117a655' => 'Label 2'
    			 );
    			 $value[] = array(
    				 'field_5cf979117a655' => 'Label 3'
    			 );
    
    	 }
    	 return $value;
     }