-
Fetch current options, and be sure to return an array if empty:
$current_options = get_option( 'option_name', array() );
-
Ensure desired options are in an array:
$desired_options = array( /* whatever you need goes here */ );
-
Merge them, using
[wp_parse_args()
]1:$merged_options = wp_parse_args( $current_options, $desired_options );
-
Update
update_option( 'option_name', $merged_options );
Of course, the trick for you is ensuring that you’re dealing with an array with your desired options. Maybe do something like so:
$desired_options = array( $_POST['import'] );
(P.S. please do some sort of sanitization. $_POST
data are inherently untrustworthy.)
Edit
I have around 30 options, inputs, booleans, textareas. They’re all
stored under XX_theme_settings and one of them is called
existing_field
Just follow the process laid out above:
-
Fetch current options, and be sure to return an array if empty:
$current_options = get_option( 'XX_theme_settings', array() );
-
Ensure desired options are in an array:
$desired_options = array( 'existing_field' => 'your string here' );
-
Merge them, using
[wp_parse_args()
]1:$merged_options = wp_parse_args( $current_options, $desired_options );
-
Update
update_option( 'XX_theme_settings', $merged_options );