How to print the output of the get_num_queries function from frontend to backend?

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();
  update_option('page_queries',$dbq);
}
add_action('wp_footer', 'get_queries_wpse_143544', 999);

Then retrieve the data with get_option.

Leave a Comment