CALL (239) 961-8285
ENDURTECH
  • Web Services
    • Web Design
      • Design and Development
      • Web Consulting and Tutoring
      • Hosting and Maintenance
      • Project Portfolio
    • Media
      • Photo and Audio, Video Editing
      • Social Media Management
      • All Web Related Services
    • Marketing
      • Digital Marketing and Branding
      • Search Engine Optimization
    • Client Portal
      • Remote Web Support
      • Web Services Payment
      • Scheduled Payments
  • Tech Support
    • Services
      • Computer Support and Repair
      • Data Backup and Recovery
      • Computer Security, Virus Removal
      • Computer Networking Support
      • Computer Consulting & Tutoring
      • All Technology Related Services
    • Blockchain
      • Blockchain Technology
      • Cryptocurrency Articles
    • Client Portal
      • Remote PC Support
      • Remote Monitoring & Management
      • Tech Services Payment
  • Articles
  • About
  • Talk to Me
  • Menu Menu

Display WordPress Database Queries and WP_Query

Web Site Support, WordPress

Sometimes, as a developer, it may be beneficial to have WordPress display is what database queries are being generated. Particularly if you are developing a custom solution for a client as we do often. To begin, simply add the follow code below to your “wp-config.php” configuration file:

 

define( 'SAVEQUERIES', true );

 

List All WordPress Queries

To list all of the database queries made for the current page, add the following code to your theme. See the WordPress Codex documentation for more details.

 

if( current_user_can( 'administrator' ) )
{
global $wpdb;
echo '<pre>' . print_r( $wpdb->queries ) . '</pre>';
}

 

In addition, you can hook into “posts_request“. You can put the code inside your child theme’s “functions.php” file.

 

add_filter( 'posts_request', 'debug_post_request' ); //debugging sql query of a post
function debug_post_request( $sql_text )

{
$GLOBALS['debugENDURTECH'] = $sql_text; //intercept and store the sql
return $sql_text;
}

 

Within your theme’s footer, you can use “print_r” to output the results as shown below:

 

print_r( $GLOBALS['debugENDURTECH'] );

 

If you are only interested in displaying what a loop is processing you can use something like the below:

 

add_filter( 'posts_request', 'dump_request' );
function dump_request( $input )

{
var_dump( $input );
return $input;
}

 

Using WP_Query

WP_Query builds a query for any type of object within the WordPress database.

Sometimes WP_Query will pass additional information into the generated SQL query. It is this function that we will want to inspect to make sure we know what it is actually transmitting!

To do this, we simply print out the SQL string WP_Query built and check it for any issues (see example below).

 

$query_args = array(
//your query arguments
);

//set results variable
$results = new WP_Query( $query_args );

//show the query on screen
echo $results->request;

 

If this article was helpful please take a moment to like us on Facebook, share this on your social media or buy us a cup of coffee.

 

January 29, 2017
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on LinkedIn
  • Share on Reddit
  • Share by Mail
https://endurtech.com/wp-content/uploads/2018/04/wordpress-content-management-system.jpg 512 512 Manny https://endurtech.com/wp-content/uploads/2018/04/endurtech-logo.png Manny2017-01-29 10:39:122019-07-04 22:24:14Display WordPress Database Queries and WP_Query
Search Search

CONNECT WITH US

This field is for validation purposes and should be left unchanged.
Engagement*

Want to say, "thanks"?
Leave me a review on Facebook and/or Google.

You can send me a tip using your Brave browser. Get Brave!

Only used to send you a receipt.
Include a Message
Popular
  • Windows Logo
    Second Monitor on Windows 10 Resets After SleepJuly 2, 2020 - 6:30 am
  • Windows Logo
    How to Disable the F1 Help Key in Windows 10April 15, 2021 - 2:40 pm
  • Cortana Logo
    How to Disable Microsoft’s CortanaApril 6, 2021 - 9:00 am
  • Firefox Logo
    How to Remove All Passwords from Lockwise in FirefoxMarch 26, 2020 - 11:00 am
Recent
  • How to Fix Brother BrLog Errors
    How to Fix Brother BrLog ErrorsAugust 24, 2026 - 10:55 am
  • How to block Facebook crawler
    List of Spider Crawlers to BlockAugust 10, 2026 - 9:20 am
  • Brave Browser Logo
    How to Fix the “Not Secure” Address Bar Err...July 20, 2026 - 12:48 pm
  • Linkpull Extension By Endurtech
    LinkPull Extension, Grab Any File From a URLJuly 7, 2026 - 7:35 pm

STAY IN TOUCH

ENDURTECH Web Design Company Naples, Florida

Endurtech GitHub ProfileEndurtech YouTube ChannelEndurtech LinkedIn ProfileEndurtech Facebook Page

5 Star Google Review for Endurtech - Naples Web Design Company

Learn More & Connect

Search Search
ENDURTECH Logo
Endurtech GitHub ProfileEndurtech YouTube ChannelEndurtech LinkedIn ProfileEndurtech Facebook Page

5 Star Google Review for Endurtech - Naples Web Design Company

Latest Articles

  • How to Fix Brother BrLog Errors
    How to Fix Brother BrLog ErrorsAugust 24, 2026 - 10:55 am
  • How to block Facebook crawler
    List of Spider Crawlers to BlockAugust 10, 2026 - 9:20 am
  • Brave Browser Logo
    How to Fix the “Not Secure” Address Bar ErrorJuly 20, 2026 - 12:48 pm
  • Linkpull Extension By Endurtech
    LinkPull Extension, Grab Any File From a URLJuly 7, 2026 - 7:35 pm

Recent Projects

  • Jewelry Website Gems of Note
    Gems of NoteNovember 15, 2019 - 10:16 pm
  • Gift Store Facebook Business Page Cover Video
    Gift Store Facebook Business Page Cover VideoApril 13, 2019 - 3:58 pm
  • Toledo Yoga BrandBot Footer Integration
    Toledo YogaApril 9, 2019 - 7:26 am
  • Lawyer Association Website with Member Portal
    National Employment Lawyers Association, Florida ChapterFebruary 26, 2019 - 8:00 am

Business Details

Mondays - Fridays
9:00 am - 5:00 pm
Eastern Standard Time
After hours by appointment

SUPPORT PHONE

(239) 961-8285

MAILING ADDRESS

59 Logan Ln.
Lynchburg, VA 24502

Copyright © 2026 ENDURTECH ® All Rights Reserved. Legal
Link to: Allow WordPress Shortcodes within Contact Form 7 WordPress Plugin Link to: Allow WordPress Shortcodes within Contact Form 7 WordPress Plugin Allow WordPress Shortcodes within Contact Form 7 WordPress PluginWordPress Content Management System Icon Link to: MailChimp Domain Verification and Authentication Link to: MailChimp Domain Verification and Authentication MailChimp LogoMailChimp Domain Verification and Authentication
Scroll to top Scroll to top Scroll to top