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($) {
console.log('myquery');
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
jQuery.post(ajax_object.ajax_url, 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;
wp_die();
}
I just get this error…
https://ibb.co/MMJz8NY
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.
Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.