Sarathlal N

Get all autoloaded option keys in wp_options table - WordPress

We can use functions like add_option() and update_option() to create options in the wp_options table.

As you noticed, the 4th parameter for add_option() & 3rd parameter for update_option() function are autoload & the default value is yes.

“Whenever a request comes to WordPress, it has to make many complicated and quick decisions in order to serve the right information to a user. One well-known way to improve the speed at which this can be done is to define certain options as needed on every page load and others as not really that important. The way you do this is by setting an option to autoload = yes. When you do that, WordPress will store all of those options into a single object and load them on every page load.”

The above statement is copied from WP VIP reference regarding options table.

I believe that you can understand the issue now. If we set our option value to autoload, it is a major performance issue. To resolve this issue, first we need to identify the autoloaded option keys in wp_options table.

Here is the quick SQL query to get all option key & data size. If your table prefix is not wp, you need to modify SQL as per your table prefix.

SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
UNION
SELECT 'autoloaded data count', count(*) FROM wp_options WHERE autoload='yes'
UNION
(SELECT option_name, length(option_value) FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 100)

Got a project in mind? Send me a quick message, and I'll get back to you within 24 hours!.

Recent Posts

  1. Disabling Payment Methods in WooCommerce Based on Conditions
  2. How to Update Product Quantity in WooCommerce Using Custom Code
  3. Dynamically Generating a Table of Contents in WordPress
  4. Direct Checkout in WooCommerce - Add Product to Cart from Checkout Page & Skip Shop, Product, and Cart Pages
  5. Understanding the Impact of git reset --hard Command

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.