Support

Account

Home Forums Add-ons Repeater Field Pre-populate checkbox choices per repeater row Reply To: Pre-populate checkbox choices per repeater row

  • Ok thanks for your reply!

    I thought I could use the acf_add_local_field instead for this, so I added the following action that displays my checkboxes correctly now:

    add_action('acf/init',	array(&$this, 'addServiceMatchMakerFilter'));
    public function addServiceMatchMakerFilter() {
    	if (function_exists('acf_add_local_field')) {
    		$posts     = new Posts();
    		$global    = $posts->getGlobalInfo();
    		$questions = $global['match_maker_questions'];
    
    		// Add field for each match maker question
    		if (!empty($questions)) {
    			foreach ($questions as $question) {
    				$choices = [];
    
    				if (!empty($question['choices'])) {
    					foreach ($question['choices'] as $choice) {
    						$value           = $choice['choice_value'] ? $choice['choice_value'] : $choice['choice_label'];
    						$choices[$value] = $choice['choice_label'];
    					}
    				}
    
    				acf_add_local_field([
    					'key'          => 'field_' . uniqid(),
    					'label'        => $question['label'],
    					'name'         => sanitize_title($question['label']),
    					'type'         => 'checkbox',
    					'parent'       => 'field_5d3ebbd2fef0c',
    					'choices'      => $choices,
    					//'layout'       => 'horizontal',
    				]);
    			}
    		}
    	}
    }

    However, when saving my post the values from these fields are empty again (also in frontend). Any idea why this is happening?

    Thanks, Toine