Home › Forums › General Issues › How to update a value in a custom field by the post id › Reply To: How to update a value in a custom field by the post id
What action is your AJAX request calling? I’m guessing you’ll just need to pass the ‘minvalue’, ‘maxvalue’, and post ID (i.e. via $_POST) to some custom handler function, for example:
function handle_slider_min_max() {
$post_id = $_POST['post_id'];
$min = $_POST['minvalue'];
$max = $_POST['maxvalue'];
update_field('slider_field_min', $min, $post_id);
update_field('slider_field_max', $max, $post_id);
}
// user logged in
add_action('wp_ajax_handle_slider_min_max', 'handle_slider_min_max');
// user not logged in
add_action('wp_ajax_nopriv_handle_slider_min_max', 'go_away');
Note: you should use the field key in update_field(), rather than specifying it by name.
Also, ‘go_away’ is not a native WP function (although it should be).
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.