0

I'm facing a quite strange issue with a simple get_comments() implementation in admin panel. Code is this (post ID is truly 1234)

get_comments('post_id=1234&status=approve');

It returns proper results if called directly, but with AJAX implementation gives just an empty array, as if no comments are found.

Ajax usage is the normal one

function my_function() {}
add_action('wp_ajax_my_function', 'my_function');

Anyone ever experienced something similar? thanks


Javascript usage

var data = {
    action: 'my_function',
};
jQuery.post(ajaxurl, data, function(response) {
    console.log(response);
}); 

AJAX/PHP part

function my_function() { 
    var_dump( get_comments('post_id=1234&status=approve') ); 
    die(); 
} 
add_action('wp_ajax_my_function', 'my_function');
  • Post the full function or it is impossible to know what happens. – cybmeta Jan 7 '15 at 11:50
  • I already debugged parameters passed through AJAX, also reducing code to minimum: it doesn't work. So: this doesn't work function my_function() { var_dump( get_comments('post_id=1234&status=approve') ); die(); } add_action('wp_ajax_my_function', 'my_function'); – a-coder Jan 7 '15 at 11:52
  • Please, edit the question and add the code there. Aslo, include the javascript part and describe the context where you are using it (front end or admin side, etc). – cybmeta Jan 7 '15 at 11:56
  • Done, as said it is implemented in admin side – a-coder Jan 7 '15 at 12:03
  • I've tested your code and I get the comments for the specified post. Are you sure there are approved comments for your 1234 post? – cybmeta Jan 7 '15 at 12:43

Your Answer

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

Browse other questions tagged or ask your own question.