Home Forums Backend Issues (wp-admin) Use ACF field selection to update another ACF field Reply To: Use ACF field selection to update another ACF field

  • Thanks for all the help, but I think this is a bit beyond me.

    I followed the ‘AJAX in plugins’ documentation, and still got an error even with the most basic example.

    Just in case theres anything glaringly obvious I’ll put the code here, but I think I’m going to try to find someone to pay to do this. I thought it’d be fairly easy but seems to have jumped in difficulty pretty quickly.

    In my functions.php…

    add_action( 'admin_enqueue_scripts', 'my_enqueue' );
    function my_enqueue() {
    	wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/my_query.js', array('jquery') );
    	// in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
    	wp_localize_script( 'ajax-script', 'ajax_object',
                array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );

    In my my_query.js file…

    jQuery(document).ready(function($) {
    	var data = {
    		'action': 'my_action',
    		'whatever': ajax_object.we_value      // We pass php values differently!
    	// We can also pass the url value separately from ajaxurl for front end AJAX implementations, data, function(response) {
    		alert('Got this from the server: ' + response);

    And at the bottom of my admin-ajax.php file…

    // Same handler function...
    add_action( 'wp_ajax_my_action', 'my_action' );
    function my_action() {
    	global $wpdb;
    	$whatever = intval( $_POST['whatever'] );
    	$whatever += 10;
            echo $whatever;

    I just get this error…

    I’m sure you have better things to do but I would be willing to pay for your time to create the code, as I don’t feel like any of this is really going in.