Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Originally I hacked together Agile Carousel and WordPress by passing wp-load.php into the AJAX script but clearly that isn't the way to go. I've now read that wp-admin/admin-ajax.php is better, but I can't yet trigger the add_action('wp_ajax_nopriv_...') method.

How can I find out what the action value is? Without knowing this, what other ways can I trigger a method that has access to all of WordPress' variables/functions?

share|improve this question
1  
Can you include the part of the javascript that makes the AJAX request? –  Stephen Harris May 2 '12 at 7:29
    
The line in Agile Carousel that fetches the data is $.getJSON("AJAX-URL", function(data) { –  MechEngineer May 3 '12 at 15:42
add comment

2 Answers 2

After some digging, I decided to try a hunch and it ended up working. Whether this is the sanctioned solution or not, but it has worked in my testing.

For the AJAX url, add the $_GET variable ?action=[ajax_action] where [ajax_action] is your requested action. (ie. http://www.example.com/wp-admin/admin-ajax.php?action=[ajax_action])

Then make add_action('wp_ajax_nopriv_...') include your action variable, ie. add_action('wp_ajax_nopriv_[ajax_action]', 'ajax_callback') and to make sure it works for logged in users, include add_action('wp_ajax_[ajax_action]', 'ajax_callback') as well.

I imagine that a similar solution would work for more generalized AJAX requests.

share|improve this answer
add comment

That action value is whatever you define - just be sure to add the same action to the source URL for the Agile Carousel - something like that: "AJAX-URL?action=carousel" ... and the hook should look about like that:

add_action('wp_ajax_carousel', 'name_of_the_function_to_call_here');
add_action('wp_ajax_nopriv_carousel', 'name_of_the_function_to_call_here');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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