get_num_queries()
Retrieve the number of database queries during the WordPress execution.
No Hooks.
Return
Int
. Number of database queries.
Usage
get_num_queries();
Examples
#1 Find out how many queries to the database the sample creates
Get the posts using query_posts() and see how many queries were made:
echo get_num_queries(); // 2 query_posts('post_type=page'); echo get_num_queries(); // 4
Notes
- Global. wpdb. $wpdb WordPress database abstraction object.
Changelog
Since 2.0.0 | Introduced. |
get_num_queries() get num queries code WP 6.8
function get_num_queries() { global $wpdb; return $wpdb->num_queries; }