AJAX in WordPress using admin-ajax.php
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about WordPress AJAX calls to PHP functions, especially for getting nonces and admin-ajax hooks working step by step.
Recommended by 2 people across 2 different months, 2019 to 2020.
What it is
A short tutorial from Zac Gordon's AJAX in WordPress course explaining how AJAX works in WordPress through admin-ajax.php. It walks through passing a nonce and AJAX URL with wp_localize_script, making the JavaScript call, hooking a PHP function into the WordPress AJAX actions, and handling the response.
What people said
Recommends mrSteveW · 2019-10 · Stack Overflow · on “After passing jQuery Ajax to PHP in Wordpress, how to update global variable prior to use in other function (without using async=false)?”
First time posting to StackOverflow. (upvotes appreciated to help me get included in the community) Despite being new to coding in general, I've been able to work out the following steps in Wordpress thanks to Zac Gordon's very helpful video [this video] and demo files [LINK] following the steps he outlines: Pass Nonce and AJAX URL via wp_localize_script Make AJAX call with Nonce and URL in JavaScript Hook PHP AJAX Function into Wordpress AJAX Hooks Use JavaScript to Handle AJAX Response Although I am able to return the expected result with the AJAX response (which I can print to console) and I am now able to retrieve a value to pass to another function, I am unable to update the value in advance
Recommends Learner · 2020-05 · Stack Overflow · on “Ajax function call to php function”
I followed the below video, step by step and it worked. Probably it had something to do with nonce AJAX in WordPress using admin-ajax.php [this video]
Cites des · 2020-02 · Stack Overflow · on “Update custom Wordpress field using AJAX”
I'm trying to update a custom field in Wordpress using Ajax (e.g having a form text input replace the custom field text by the click of a button). I’m using the Advanced Custom Fields plugin and following the example I found here but this doesn't seem to work: [LINK] What I have done is: (1) Add html form to my single-(post-type).php <form id="test-form" action=""> <input type="text" name="input-test" value="<?php the_field('field-name'); ?>"> <input type="submit" value="Update"> </form> (2) update_field function in functions.php (this is an ACF function) function test_function() { $input_test = $_POST['input-test']; if (!isset($input_test) || $input_test == "") { $input_test = "Fall Back";