Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

$wpdb->get_results

used for getting result from database also this is not working

$wpdb->queries

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
add comment

8 Answers 8

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
add comment

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
add comment

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'] ) )
        return;
    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
add comment

I prefer Debug Bar.

Screenshot of Debug Bar running on WordPress 3.2.1

share|improve this answer
add comment

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
add comment

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.