Home › Forums › Front-end Issues › Reverse query › Reply To: Reverse query
This is my ajax function if it helps at all
function add_user_to_cleanup() {
$add_remove = $_POST['add_remove'];
$cleanup_id = $_POST['cleanup_id'];
$user_id = get_current_user_id();
$volunteers = get_field('field_57e89bd93b402', $cleanup_id, false);
if (empty($volunteers)) {
$volunteers = array();
}
if ($add_remove == 'add' && !in_array($user_id, $volunteers)) {
//if user is not in volunteers array then add them
array_push($volunteers, $user_id);
} elseif ($add_remove == 'remove') {
//find user in array and remove them
$pos = array_search($user_id, $volunteers);
unset($volunteers[$pos]);
}
update_field('field_57e89bd93b402', $volunteers, $cleanup_id);
}
add_action( 'wp_ajax_add_user_to_cleanup', 'add_user_to_cleanup' );
add_action( 'wp_ajax_nopriv_add_user_to_cleanup', 'add_user_to_cleanup' );
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.