Question

I've looked at the Settings API codex page, https://codex.wordpress.org/Settings_API, and I can't find anything related to setting autoload to no for any options using the Settings API.

Is there any way to achieve this using the Setttings API? Asking because I have many DB table options entries that were created using register_setting and all of the options have autoload set to yes.

I need to optimize this because hundreds of entries are being loaded on every page load unecessarily.

Était-ce utile?

La solution

The only way to accomplish this is to add the option to the database yourself before the Settings API does so. To do this, add a 'sanitize_callback' to the register_settings function:

register_setting ('my_options', 'my_option_name', array ('type' => 'string', 'sanitize_callback' => 'my_function_name'));

Then, in your function, update the option yourself:

function my_function_name ($value) {
    update_option ('my_option_name', $value, false);
    return $value;
}

`

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top