Support

Account

Home Forums ACF PRO Save value in ACF Relationship Field via AJAX

Helping

Save value in ACF Relationship Field via AJAX

  • Hello,
    I want to create user based “read later” list.
    I’ve created a ACF relationship field in the user profile – but now I’m not sure how to proceed. Should I create a discrete PHP file which will be called via AJAX ? I think that in this case the WP enviroment is not loaded and I cant use the WP oder ACF functions ? Or should I write a PHP function in functions.php ?

    I think I will need something like this:

    
      $user = wp_get_current_user();
      $user_id = $user->ID;
      $readlater = get_field('user_readlater', "user_{$user_id}", false);
      // see if the value is already added, if not add it
      if (!in_array($post_id, $downloads)) {
        $readlater[] = $post_id;
        // and update the field
        update_field('user_readlater', $readlater, "user_{$user_id}");
      }
    

    Cloud anone give me a hint?

  • All the information you need for doing AJAX can be found here https://codex.wordpress.org/AJAX_in_Plugins

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Save value in ACF Relationship Field via AJAX’ is closed to new replies.