How to use several wp_ajax_ functions for different queries?

I am working on getting multiple functions to work with wp_ajax_ and the first two functions fire just fine. However I have the need for a completely new query that will take advantage of AJAX also.

  • Should I beef up my first function with conditionals? Or
  • Can I init more than one wp_ajax_ function like my code below?

My code so far:

Read More
add_action( 'init', 'my_ajax_init' );
function my_ajax_init() {
   add_action('wp_ajax_nopriv_wpa56343_search', 'my_ajax_search');// works
   add_action('wp_ajax_wpa56343_search', 'my_ajax_search'); // works

   add_action('wp_ajax_nopriv_nogeo_results', 'nogeo_search'); // does not
   add_action('wp_ajax_nogeo_results', 'nogeo_search'); // does not
}

my_ajax_search is functioning fine with my JS AJAX calls. nogeo_search is not. My question is – is what I am doing to declare my ajax functions correct? If it is not correct please explain how to use wp_ajax_ with multiple callback functions.

Related posts

1 comment

  1. I was able to get multiple wp_ajax_ functions to declare callback functions like this:

    add_action( 'init', 'my_ajax_init' );
    function my_ajax_init() {
        add_action('wp_ajax_nopriv_wpa56343_search', 'first_search');
        add_action('wp_ajax_wpa56343_search', 'first_search');
    }
    
    add_action( 'init', 'my_ajax_no_geo_init' );
    function my_ajax_no_geo_init() {
        add_action('wp_ajax_nopriv_nogeo_results', 'second_search');
        add_action('wp_ajax_nogeo_results', 'second_search');
    }
    

Comments are closed.