Support

Account

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).