I'm trying to develop a simple plugin and figure out how to display the number of queries executed in frontend, to an admin page (plugin options page), using get_num_queries() function.

I've added the following code to my plugin's function file and works well showing (in my footer) the number of queries processed to create the frontend page:

function get_queries() {
$get_queries ='';
$get_queries .= get_num_queries();
$get_queries .= ' queries';
echo $get_queries;
add_action('wp_footer', 'get_queries', 999);

If I use echo get_queries(); in the place where I want to display the value in my plugin page, it display the number of queries processed in the plugin options page, not from frontend.

My question is: how to print the number of queries processed to create the frontend page in my plugin options page?

1 Answer 1


Each HTTP request is a new one so you will need to save the data to the database. You can't just "pass" the data from the front to the back end.

function get_queries_wpse_143544() {
  $dbq = get_num_queries();
add_action('wp_footer', 'get_queries_wpse_143544', 999);

Then retrieve the data with get_option.

  • Is there a way to perform a "hidden" HTTP request on frontend on plugin activation since it not dispay any values if no user visit the site? Should I ask a new Question?
    – Knott
    May 6, 2014 at 17:07
  • You can do thAT with AJAX.
    – s_ha_dum
    May 6, 2014 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.