I am trying to update an existing ACF field using update_field, when a user clicks on one of the links below. The field is automatically set to “Pending” status when a new event is made. When the event is pending, the user is given the option on the frontend whether to accept or reject the event. Should the event be accepted, for example, the “Pending” in the current field will be updated to “Accepted.” Same case with “Rejected.” This is my HTML:
<a class="accept-button" onclick="">Accept</a>
<a class="reject-button" onclick="">Reject</a>
This is in the function.php of my theme:
function accept_event() {
$value = $_POST['Accepted'];
update_field('field_53bc53fb91487', $value, $event_id);
}
function reject_event() {
$value = $_POST['Rejected'];
update_field('field_53bc53fb91487', $value, $event_id);
}
I’m aware that there are two ways to do this. One that requires a refresh of the page, and another that uses AJAX. I’d prefer to just refresh the page instead of using AJAX. I believe I can achieve this using Javascript? If so, I’m not really sure how to go about it. Any suggestions? Thoughts? Any and all help is much appreciated!
Thanks!
you can try the following code
in updateStatus.php
Note: code is not tested so might have some syntax error and you might also need to change a few thing according to your needs but I guess you will get the idea how it will work
Also this javascript code required the use of jQuery