Support

Account

Home Forums ACF PRO User taxonomies Reply To: User taxonomies

  • 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
      }
    
      }
    
    }