0

I use a function to "pass" the data with get_num_queries from the front to the back end (to a plugin options page).

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

(*thanks to @s_ha_dum for the function)

The problem is retrieving the data with get_option will not display any data until the front end page is not visited at least once.

My question is obviously: how to perform a hidden frontend HTTP call with AJAX after clicking "Save Settings" button so that the get_option to display the value from the above function after the options page will be reloaded?

Thank you!

1

With that code in place, all you should need to do is poke the page with wp_remote_get() as your backend page loads, and before you need to retrieve the option value. By doing this, you avoid the possibility that no visiter has visited the page. Your request will be that visitor.

The function is fairly self-explanatory:

$response = wp_remote_get( $url, $args )
  • I accepted your answer because I have the feeling it is the right direction but can you please elaborate a bit your answer? – Knott May 6 '14 at 20:30
  • Brilliant! I used $url = get_site_url(); before echo $page_queries; I had not thought to such a simple approach. Thanks a lot! Since all this generated another query to display the data, my main concern is now to nullify that extra query appended by function. But I think it is impossible :) – Knott May 7 '14 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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