WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on wordpress which is new to me Now I have been provided with site completely designed in wp But the problem is I am unable to search the query for each functionality/page I found


used for getting result from database also this is not working


Is there any way to print each query currently executing?.

Please Help.

share|improve this question

migrated from stackoverflow.com Nov 9 '11 at 5:09

This question came from our site for professional and enthusiast programmers.

Do you want to see the SQL query being executed? – Rutwick Gangurde Nov 9 '11 at 5:18
Not that I would discourage getting to know the internals, but this hints at another question whose answer would be very different. What problem are you trying to solve? – Annika Backstrom Nov 9 '11 at 14:55
up vote 1 down vote accepted

Debug bar is one of the recommended (by WordPress) plugins to install for theme and plugin development. I also use debug-bar-extender: http://wordpress.org/extend/plugins/debug-bar-extender/

share|improve this answer

For $wpdb->queries to work you need to configure in wp-config.php:

define('SAVEQUERIES', true);

This is highly not recommended for production (heavy performance hit) and so turned off by default.

share|improve this answer
This is the perfect way... +1! – Rutwick Gangurde Nov 16 '11 at 6:15
Rutwick Gangurde ok thanks – Sparkx Nov 17 '11 at 13:07

I often do this when I need to check the current query:

add_action( 'wp_head', 'show_current_query' );

function show_current_query() {
    global $wp_query;

    if ( !isset( $_GET['q'] ) )
    echo '<textarea cols="50" rows="10">';
    print_r( $wp_query );
    echo '</textarea>';

To show the current query, just add ?q into the current URL.

This will show the current query (stored in global variable $wp_query), including the SQL query and all other query variables.

share|improve this answer

I prefer Debug Bar.

Screenshot of Debug Bar running on WordPress 3.2.1

share|improve this answer

The global $wp_query contains everything about the current query, including the arguments, results, contents of the results, and the query itself.

$wp_query->request should do the job for you here.

share|improve this answer

You could also use the WPDB Profiling plugin that will display all SQL statements that were run to generate the page you're currently on, at the bottom of the page.

share|improve this answer

You can use the Wp Pear Debug plugin. It will show you a list of the queries executed in the page, the number of seconds those queries took to execute and the php function which initiated the query. Please note that you must save the settings at least once before it begins working.

share|improve this answer

No need to install any plugin, you can use this:

$queried_object = get_queried_object();
var_dump( $queried_object );

Source: Codex

share|improve this answer
<?php $wpdb->show_errors(); ?>  // use syntax just before your query 
<?php $wpdb->print_error(); ?>  // user after your query execution


<?php $wpdb->show_errors();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.