Hey there! I'm currently working on a CLI tool to deploy WordPress apps to DigitalOcean. Check it out! It's free and open source.
I’ve never been a fan of IDEs, complex debugging tools with breakpoints, variable watch lists and all that fancy stuff.
print_r() have always been my best friends.
Recently I was playing around with the caching arguments in
WP_Query, trying to combine that with
update_meta_cache() while sticking
wp_suspend_cache_addition() somewhere there in the middle, and it quickly became a mess, so I wanted to know what queries am I actually running under the hood.
I came up with this little piece, which I think I’ll use more often from now on:
// Assuming SAVEQUERIES in set to true. $GLOBALS['wpdb']->queries = array(); // All the magic goes here var_dump( $GLOBALS['wpdb']->queries );
This gives you a nice list of SQL queries that were triggered only by that magic code in between. Works great when you need a quick sanity check on all those caching arguments, priming meta or term caches, splitting queries and whatnot.
Obviously it empties the initial set of queries, so anything in Debug Bar, Query Monitor, etc. will no longer be accurate.
What’s your favorite way to keep track of queries?