I'm doing a function which requires the use of the wp_ajax action.
I've followed this guide to set it up with the differences of adding the requesting the object AJAX file in functions.php and also added
if(isset($_REQUEST['action'])) {
do_action('wp_ajax_'.$_REQUEST['action']);
do_action('wp_ajax_nopriv_'.$_REQUEST['action']);
}
to make it work.
Issue is that obviously having the file in functions.php causes every page to initialise workflow, but I only want it on one particular template file.
I could add it as a plugin I'm aware, but certain functions used are global to the theme and will never be used on any other theme so doesn't make sense in my mind to do that.
Ideally, I would just like to do require('ajax_file.php'); in the template file, but that's the main issue here is I don't think I can (unless somebody can correct me). So if there is an easy way to call it from the functions.php file without every other page also calling it then that would be a massive help.
Thanks!
$_SERVERto detect the page but if the URL changes then it's case of diving back into the code to fix it. – WolfieZero Apr 26 '12 at 10:56add_action('wp_ajax_<action>', 'do_my_action');followed by ado_action('wp_ajax_<action>');is same as callingdo_my_action. Do you really need ajax for this purpose. – KDM Jun 12 '12 at 8:53