I have this ajax call which gets the value for catname:
jQuery('.bio a').click( function(){
var catname = $(this).closest(".bio").data('category');
alert(catname);
jQuery.ajax({
cache: false,
type: 'POST',
url: 'http://www.mysite.com/wp-admin/admin-ajax.php',
data: {
action: 'performers',
catname: catname
/*nonce: nonce,*/
}
});
});
I have this function which updates a custom field:
function performers(){
$test = $_POST['catname'];
return $test;
}
add_action('wp_ajax_nopriv_ performers', 'performers');
add_action('wp_ajax_performers', 'performers');
I use the $test variable in single.php
Questions:
Any idea why is this code not working? jquery var catname is being set (tested this with the alert). Maybe it has to do with caching? I did try to update a custom field with $test variable and retrieve the value of that custom field in single.php, still no luck.
I saw a tutorial using nonce? Do you advise me to use it? How?
I have tried this, still no luck (called performers(); in single.php in order for it to work.
function performers(){
$test = $_POST['catname'];
update_post_meta(758, 'perfx', $test);
}
add_action('wp_ajax_nopriv_performers', 'performers');
add_action('wp_ajax_performers', 'performers');
wp_ajax_nopriv_ performers
should bewp_ajax_nopriv_performers
(no spacces)