How to Debug WordPress Query
WordPress offers the best across the board and easiest debugging tools available. Many users simply do not take the time to see what is available to them. The hard work has been done. By exploring the WordPress site and exploring the tools predesigned, much of the work and frustration is eliminated. These tools are designed to help you monitor your site and get rid of the things that cause you issues. Usually those things are caused from third party plugins. By spending a little time in the WordPress Codebase you will find life just got much easier. The customization that is available helps you design a site that you can work with efficiently and errors and warnings can be dealt with quickly and easily. WordPress is so popular, that finding someone to assist if never more than a few clicks away.
Not debugging your site or not correcting offending issues, even if hidden will affect your site performance. It can take up needed memory and reduces performance. It also will use up disk space. Your goal is to produce an error free site. These tools will get you as close to that as is possible.
As with any system, you will need to debug PHP code. WordPress has a built in debugging system to make this process much easier. We are going to describe multiple tools for debugging WordPress. We will also discuss a standardize code that functions across plugins, themes and the core.
It is highly recommended for code developers to account for WP_DEBUG in plugins and themes. Though it is not mandatory, it is advised to use WP_DEBUG mode while writing and standardizing code planned to be released publically. This insures the plugin and theme is compatible with the code of other developers. If it is not compatible it is impossible to use and will prevent your theme from being promotable via WordPress tools on the WordPress official site. It insures the integrity of your code as well.
WP_DEBUG (as well as other debug tools) are meant for local testing and staging installs. They are not recommended for use on live sites.
Listen to the Latest Episodes Right Now.
Define ‘WP_DEBUG’ true
Define ‘WP_DEBUG’ false
Do not add apostrophes around the words (true/false)
PHP Notices, Errors and Warnings
By enabling the WP_DEBUG system, al PHP errors, warnings and notices will be displayed. This is assumed to adjust the default of the system of PHP with only shows fatal errors. It also will sometimes show a blank white screen when an error is reached. For this reason the modification was made. Due to this modification, sometimes an error will display when nothing seems to be amiss. Usually that means proper data validation conventions inside the PHP were not followed. Once the code has been identified these warnings are an easy fix resulting in code that is easier to maintain.
There may be functions or function arguments within WordPress that your site is currently using that may be slated for deletion in the near future. Enabling WP_DEBUG will activate notices about the coming deletions and often will suggest a new function that should be used in its place. When the currently used functions are removed from the core code, the change will be seamless for you as it was already addressed.
A companion to WP_DEBUG is the WP_DEBUG_LOG. This program causes all errors to be saved on a debug.log file inside wp-content/directory. This is for use in the instances when you want to view or review all the notices generated while off-screen. WP_DEBUG must be enabled (true) in order for WP_DEBUG_LOG to function.
The code below, placed in your wp-config.php file, will record (log) all errors, notices, and warnings. It logs them in a file called debug.log in the wp-content directory. It will also hide the errors.
You must insert this BEFORE /* That’s all, stop editing! Happy blogging. */ in the wp-config.php file
// Enable WP_DEBUG mode define(‘WP_DEBUG’, true);
// Enable Debug logging to the /wp-content/debug.log file
// Disable display of errors and warnings
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
This companion to WP_DEBUG controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings If you wish to hide the errors and warnings, set this to false.. Use this with WP_DEBUG_LOG so that errors can be reviewed
Savequeries saves the database queries to a group or array. That selection can be displayed to allow you to evaluate those queries. The queries explains the cause, the length of time to execute and what function called the query. Be sure to turn this function off when you are not debugging. It will have an impact on your site.