Print Mysql query in WordPress from WP_Query

on

How to print Mysql query in WordPress ?

WP_Query function is used in WordPress to build query. This is very simple format of argument passing job to get required output. But while building complex query we may start to think “How can i see this query in Mysql format”.Is that possible ? Yes it is, Possible ! WordPress opens the
door even for that.Check below step to print the WP_Query function in Mysql format.

Step 1 : Define SAVEQUERIES as true in wp-config.php as bellow

define('SAVEQUERIES', true);

Step 2 : Place the below code in your footer section.


if (current_user_can('administrator')){
    global $wpdb;   
    print_r($wpdb->queries);   
}

That’s all just refresh your page, then see the printed Mysql query in array format.

Sniper Elite V2 [Online Game Code]

Posted in Wordpress and tagged by .

About Gowri

I am professional web developer with 4+ years experience. PHP, jQuery, WordPress, Magento and Symfony2 are my key skills in web development. I am working with strong enthusiastic team with spirit. We provide all web related solution like HTML/CSS development, Web graphic design and Logo.