I am trying to AJAX in a php file that uses Advanced Custom Fields fields, and get a 500 internal error when making the request. The php file works fine if I just use ‘include’, but I need to have it be dynamic in my JavaScript. My AJAX knowledge is limited but have started with this:

$(this).load('/wp-content/themes/theme-name/template-parts/uploads.php', function() { console.log('success'); });

That works to call basic text on the page, but as soon as I put in an ACF field, I get the 500 error.

  • Where do you want to include it? On what page - front-end or back-end? Can we see the code in your PHP file? Have you attempted any AJAX code?
    – Sally CJ
    Jun 18, 2019 at 0:14
  • Just added the AJAX that I have tried. It is for a front-end page template.
    – jons
    Jun 18, 2019 at 0:19

1 Answer 1


Sending an AJAX request to a specific file is not the way to do AJAX in WordPress. This is because WordPress itself is not loaded by your file, so you wouldn't be able to use WordPress functions without an error.

There are two proper ways to handle AJAX requests in WordPress:

  • Thank you, Sir. I will look into it. I appreciate your time!
    – jons
    Jun 18, 2019 at 1:22

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.