Support

Account

Forum Replies Created

  • What a time-saver! Thanks, John!

  • That’s great news, Fletch! Thanks for updating us.

  • +1

  • Also, thank you. I didn’t realize I needed to concatenate ‘user_’ to $user_id for update_field(). That was the last bit I needed for my field update to work.

  • @fountain I can confirm it works. However, after you update the field, you also have to manually attach the user id to the terms ids in the wp_term_relationship table using wp_set_object_terms(). Otherwise the terms ID’s will be meaningless. WordPress won’t understand those terms are associated with the user.

    Also, I’m not sure but you may need to pass the updated field value as an integer and not a string. Maybe also as an array. I’m not sure what update_field checks for.

    In my case, I have several terms that I need to associate with each user.

    Here’s what I’m using and it works. Keep in mind I’m hooking into gform_user_registered so I can access data submitted through the Gravity Forms user addon form ($feed and $entry, respectively). Sorry for the sloppy comments below, I’m in a bit of a hurry:

    
    add_action( 'gform_user_registered', 'wda_add_expertise', 10, 4 );
    
    function wda_add_expertise($user_id, $feed, $entry) {
    
      $terms = rgar( $entry, '7' ); //get Gravity Forms multiselect field values.
    
      if ($terms) {
       
    
      // An array of IDs of categories we want this user to have.
    
      $cat_ids = json_decode($terms); // must convert Gravity Forms json to array of integers
    
      // Update ACF
    
      update_field('ares_of_expertise', $cat_ids, 'user_' . $user_id);
    
      // Connect terms with user
    
      /*
       * If this was coming from the database or another source, we would need to make sure
       * these were integers:
     */
    
      $cat_ids = array_map( 'intval', $cat_ids );
      $cat_ids = array_unique( $cat_ids );
    
      // Connecting taxonomy ID's for custom taxonomy "expert" to user ID
      wp_set_object_terms( $user_id, $cat_ids, 'expert' ); 
    
     }
    
    }
  • IF anyone is interested, I got it working.

    For some reason the field had a random name instead of the one I gave it in the ACF admin screen. I left a little snippet in so you can easily find the field name through debugging. There is probably a better way to do this but I’m not intimately familiar with all things ACF.

    Also note that my custom taxonomy is “expert” so change that out for yours.

    add_action('edit_user_profile_update', 'wda_connect_user_terms');
    add_action('personal_options_update', 'wda_connect_user_terms');
    
    function wda_connect_user_terms($user_id) {
    
      $terms = $_POST["acf"]['field_59eeaa8ebb291'];
    
    // comment in this snippet to find field name
    /* $fields = $_POST;
     * echo '<pre>';
     * var_dump($fields);
     * echo '</pre>';
    */
    
      if ($terms) {
       
      // An array of IDs of categories we want this post to have.
      $cat_ids = $terms;
    
      /*
       * If this was coming from the database or another source, we would need to make sure
       * these were integers:
      */
    
      $cat_ids = array_map( 'intval', $cat_ids );
      $cat_ids = array_unique( $cat_ids );
    
      $term_taxonomy_ids = wp_set_object_terms( $user_id, $cat_ids, 'expert' );
    
      if ( is_wp_error( $term_taxonomy_ids ) ) {
        // put debug code here
      } else {
        // put debug code here
      }
    
      }
    
    }
  • Hi all,

    I installed LH User Taxonomies and created a taxonomy with the suggested snippet in the plugin’s description.

    I then created an ACF taxonomy field for user objects. I can save terms via that field on the user edit screen and they save perfectly, but they aren’t able to connect a term object to a user object via the wp_term_relatinoships table – as @elliot mentioned he implemented in ACF 5.4.0, above.

    Has any one had any success with this? Is there a good workaround for hooking into the ACF save process like @rowanpurdy suggested?

    @arcanepsyche, @jivedig, @lbonner – you guys have any success? Because of Elliot’s updates on this thread I was expecting that part of the process to work natively with ACF.

  • @mattrad-8q962886d4 I’m pretty sure that’s the same snippet I’m using. It does work in the sense that the activation key is activated in the ACF backend, but ACF continues to act like it’s not when I update. I have to deactivate the key and reactivate it manually. It’s happening on all of my and my clients’ sites.

    It was working for a while though. Not sure what changed.

  • Also, it seems like @elliot changed something because that snippet from @jacobdubail stopped working for me. It still populates the field for me but ACF still acts like the key isn’t entered when I go to update. I then have to deactivate the license key and activate all over again. Then ACF will update.

    It’s like Elliot added a second value that the manual activation process creates in the DB and the plugin checks for before updating. Elliot, is there any possible way to do this and not violate what you’re trying to do with your plugin, business-wise? Or is that not an issue and I am just doing it wrong?

    Any one else run into this?

  • +1 for a wp-config constant.

    I use ManageWP and I create my sites with script and wp-cli. Honestly, I’d pay an annual fee for this plugin every year. That’s how much I use and like it. But the lack of a constant is tough.

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

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.