After looking through the jQuery documentation and many stackexchange community forums, I am still faced with this problem. Taking little bits from here and there have helped me get this far, but I am stuck where I am now.

Im using an ajax request to try and load the next post after the one that is currently displayed. The only issue I run into is when I try to execute the method included in my php file:


echo getnext();

function getnext(){

$post = get_post($_POST['id']);

$prevPost = get_previous_post();

return $prevPost->post_content;


I can echo the POST variable that is being passed in fine, but once I try to actually call the method I get a 500 internal Server Error.

My AJAX request looks like this:

      setTimeout(function (){

$currid = $('#post_id').val();

                alert (data);

$('#academiccontent').animate({ 'opacity': 1 });

 }, 1000);

Any help would be greatly appreciated, Ive been stuck on this for a long while now.


  • 1
    There are a lot of questions here regarding the use of AJAX in WordPress, I suggest starting there, as well as reading about AJAX in the Codex.
    – Milo
    Commented Jul 16, 2014 at 20:03

1 Answer 1


The URL you are trying to pass to cannot be used (wp-content/themes/stargazer/populate.php)

As @Milo pointed out, please check the AJAX Codex, and it will explain the use of 'ajaxurl', which is a protected variable.

In short, all AJAX requests must be passed through 'admin-ajax.php' whether it is for the frontend or backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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