I have a simple PHP based counter Wordpress function that updates the user meta every time the page is loaded.
What I would like to do is only run this function when a particular button is clicked.
My button markup
<a class="button" id="interaction-count" href="#">Interaction</a>
My current PHP function (Which currently runs, and updates the user meta, on each page load)
function setCvDownloads($postID) {
$count_key = 'download_count';
$count = get_user_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_user_meta($postID, $count_key);
add_user_meta($postID, $count_key, '0');
}else{
$count++;
update_user_meta($postID, $count_key, $count);
}
}
Is is possible to run this when the interaction-count button is clicked instead? I assume some AJAX would be involved? If someone couple point me in the right direction that would be great
interaction-countbutton is clicked and also yes, ajax would probably be the best option.$myValuevalue...$myValueanywhere in your function.