Support

Account

Home Forums Add-ons Repeater Field Problem dynamically loading options for a child of repeater field

Unread

Problem dynamically loading options for a child of repeater field

  • Hello,
    I’ve used this function in the past to load the possible values of a field.

    
    add_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
    function load_combine_fields($field)
    {
    	$productGroupID = $_GET['tag_ID'];
    	//get the field value of "filter" from the product group without loading the field
    	remove_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
    	$filters = get_field('filter', 'product_group_' . $productGroupID);
    	add_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
    
    	$field['choices'] = array();
    	if ($filters != null && is_array($filters)) {
    		foreach ($filters as $filter) {
    			$options = $filter['filter_options'];
    			foreach ($options as $option) {
    				$field['choices'][sanitize_title($option['value'])] = sanitize_title($option['value']) . ' (' . $filter['filter_title'] . ')';
    			}
    		}
    	}
    	error_log(print_r($field['choices'], true));
    	//$field['choices'] = array('1', '2', '3', '4');
    	return $field;
    }
    

    Nowadays it does not do anything. The log is beeing created so the function IS running, but the field options are just not beeing set.

    Note: I think it has something to do with the “combine” field beeing a child of the repeater field “filter”. If I move the field outside the repeater, everything works.
    Also: If i comment out everything but the hard coded choices at the end, the options are beeing set as 1,2,3,4.

    Thanks!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.