Support

Account

Home Forums ACF PRO Pre-populate Relationship field with (default) value if not already set Reply To: Pre-populate Relationship field with (default) value if not already set

  • Hi @jacobraccuia

    Thanks for the post.

    You are right, the field type does not contain a default_value argument within its settings array. As a workaround, you could load the new value to the ‘value’ array like so:

    add_filter('acf/load_field/key=field_58f0632672126', 'rel_field');
    function rel_field($field) {
    
    	$slider_id = isset($_GET['slider_id']) ? $_GET['slider_id'] : null;
    	if(isset($slider_id)) {
    	    $field['value'] = $value;	//pass an array with the new value(s)	
    	}
    	
    	return $field;
    }