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.

I have an AJAX request that retrieves information from a function I coded in my own plugin, here is how I set the ajax function:

function my_ajax_function () {
   do_action('my_plugin_function');
}

add_action('wp_ajax_do_ajax', 'my_ajax_function');

Complete file code at this link, will be temporarily available until we get a reply, I commented the line where the request fails, hope it helps:

http://www.pokebeach.com/code.txt

In the jQuery script I'm able to do the AJAX call but it is returning nothing and it seems that my plugin is not loaded when calling the functions via AJAX, also I know the functions work correctly because I use them in other places in the website where they return the proper data, is there any configuration or something to do with this, so the plugin works with the AJAX requests?

Thanks!

share|improve this question
    
do_action() does not return a value you could echo. Does it work when you echo a string? See also Debug AJAX. –  toscho Jun 10 at 4:50
    
Well I was going to remove the echo because the function is simply not called. –  Ultranuke Jun 10 at 4:50
    
Why don’t you use your plugin function as a callback? –  toscho Jun 10 at 4:53
    
Do you mean calling them directly? if yes, then I receive an error saying the function is not defined. :S –  Ultranuke Jun 10 at 4:56
    
Please add the complete code to your question. There is a logic error somewhere. :) –  toscho Jun 10 at 4:57

1 Answer 1

//This is the function that fails when calling the function via an AJAX request.
$context['stories'] = apply_filters('xfwpint_get_slider_post_data', $context['stories']);

When calling via ajax , you have to include file in your ajax action function, file in which you have defined your filter, so it gets called.

For e.g.

require_once('./my_file_containing_filter_function');
share|improve this answer

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.