get_num_queries()WP 2.0.0

Retrieve the number of database queries during the WordPress execution.

No Hooks.

Return

Int. Number of database 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.

Code of get_num_queries() WP 6.0

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