get_field() not working in standalone PHP file
-
Hello there – I’m pretty new to WordPress development so apologies if I’m misunderstanding any basic fundamentals here. My site is currently hosted locally, and I’m trying to update an ACF repeater field dynamically.
I have a page that runs this code:
url: 'http://localhost:8888/wordpress/wp-content/themes/cookable/write-course-to-user.php',data:{"userIDdata":finaluserid, "courseURLdata":tidycourseurlupdate}, success: function(data) { $('#result3').html(data); } });And then write-course-to-user.php – a standalone PHP file – contains:
<?php $userIDfinal = isset($_REQUEST['userIDdata'])?$_REQUEST['userIDdata']:""; $courseURLfinal = isset($_REQUEST['courseURLdata'])?$_REQUEST['courseURLdata']:""; $field_key = "field_61e9bb8b66765"; $value = get_field($field_key, "user_{$userIDfinal}"); $value[] = array("course_slug" => $courseURLfinal); update_field( $field_key, $value, "user_{$userIDfinal}"); ?>However I’m getting errors:
Call to undefined function get_field()I assume that the ACF/Wordpress functionality is not working in the standalone file. I’ve tried adding:
include('http://localhost:8888/wordpress/wp-config.php'); include('http://localhost:8888/wordpress/wp-load.php'); include('http://localhost:8888/wordpress/wp-includes/pluggable.php');but still no joy. If anyone could point me in the right direction here I’d be very grateful.
Thanks so much.
The topic ‘get_field() not working in standalone PHP file’ is closed to new replies.