get_num_queries()WP 2.0.0

Gets the number of queries that have been made to the WordPress database before this function is called.

No Hooks.

Returns

Int. Number of queries.

Usage

get_num_queries();

Examples

0

#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() code WP 7.0

function get_num_queries() {
	global $wpdb;
	return $wpdb->num_queries;
}