admin管理员组文章数量:1122826
I'm trying to update option_name values from my form fields on form submission
// Update value from wp_options 'oxymade_colors' name (--primary-color)
// Used to update the rgb color
$color_mappings = array(
'field_1047' => '--primary-color',
'field_1088' => '--secondary-color',
);
// Retrieve the entire array from the database
$oxymade_colors = get_option('oxymade_colors');
// Check if the array is valid and contains the 'colors' key
if (is_array($oxymade_colors) && isset($oxymade_colors['colors'])) {
// Loop through the field mappings
foreach ($color_mappings as $field_id => $option_name) {
// Get the submitted value for the current field
$new_color_value = isset($submit->meta[$field_id]['value']) ? $submit->meta[$field_id]['value'] : '';
// Loop through the 'colors' array to find the current option name
foreach ($oxymade_colors['colors'] as &$color) {
if (isset($color['name']) && $color['name'] === $option_name) {
// Update the value
$color['value'] = $new_color_value;
break;
}
}
}
// Update the entire array in the database
update_option('oxymade_colors', $oxymade_colors);
}
}
Everything works as expected and I'm able to update the right name in the array. Also I can see the new value in the database and in the plugin settings.
However these changes are not reflecting in the frontend. I need to go to the plugin settings, only press the update button and magically (although nothing changed in the database), I can see the result.
I'm not sure what I'm missing since the database is updated correctly. Any action missing?
本文标签: functionsHow to trigger an updateoption
版权声明:本文标题:functions - How to trigger an update_option 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299886a1930618.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论