Home Forums General Issues Ajax error: Class acf_field not found. Reply To: Ajax error: Class acf_field not found.

  • You mentioned when you loaded the .php file directly, does this mean this isn’t a part of a WordPress page? A stand-alone PHP page? I’m not sure whether ACF fields would be accessible through this or not, i’d guess not.

    You’d be better off adding a php callback function for your ajax in your functions.php file.

    Here’s a simple example of getting a field with AJAX:

    In your functions.php:

    add_action('wp_ajax_getdatefunction', 'getdate'); 
    add_action('wp_ajax_nopriv_getdatefunction', 'getdate'); 
    function getdate(){

    In your JS file:

    		type: "POST", 
    		data: 'action=getdatefunction',
    		cache: true, 
    		success: function(results){
                            alert('The date is: '+results);