my single posts is getting 31 query from mysql. I checked all queries. I saw this query.
I am using last posts and categories widget. I think there query is unnecessary.How to remove theme
Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_pages' LIMIT 1 Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_calendar' LIMIT 1 Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_tag_cloud' LIMIT 1 Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_nav_menu' LIMIT 1
my sidebar is here https://gist.github.com/4546327
Best I can tell is that those default widgets get options from the database as their classes are constructed, so there’s no way to prevent the DB queries without disabling those widgets entirely. Depending on your needs, you may want that slight performance bump and do not need the widgets, in which case you can use this code to disable them (place in functions.php):
See here for more default widget class names:
http://codex.wordpress.org/Function_Reference/unregister_widget
UPDATE:
I did some more research and discovered that these four widgets do not have any auto-loaded options, even though several other widgets do have auto-loaded options set in the
wp_install_defaults()
function in/wp-admin/includes/upgrade.php
. This may be an oversight. In any event, if these widgets have never been loaded into a sidebar, theWP_Widget
parent class or the widget class have never had the opportunity to set any defaults. The other widgets are constructed and useget_option()
but don’t produce a query because they’re autoloaded with lots of other WordPress options. These four don’t have autoloaded options soget_option()
has to query the database for each.The simplest solution is just to assign defaults when the theme is first activated, like so:
From a glance at your Code, your
sidebar.php
is quite extensive and variable.The Options are not directly loaded in your
sidebar.php
, I suppose them to be loaded in your widgets, of which you seem to have a few. As your Theme seems to have a lot of Options available, you need to load all those values to ensure all features.I strongly recommend not messing with the code in this case, as you could lose features you may later need, and the 4 calls of
get_option()
that produce the above query should be handled in no time.