Home Forums ACF PRO User taxonomies Reply To: User taxonomies

  • Hi all,

    I would really appreaciate some advice on the best way to resolve a problem with the Taxonomy Field Type when applied to Users.

    I have categories and custom taxonomies set up as taxonomy fields with the field group set to appear on user profiles. The taxonomy field type is checkbox with allow multiple select, Load and Save options set to Yes.

    After editing a user profile ‘John Doe’ and selecting terms from the taxonomies the term_ids are correctly stored as a serialized array in the wp_usermeta table. However the entries that are created in the wp_term_relationships table have object_id = 0, rather than the user_id for ‘John Doe’. When I edit another user profile ‘Fred Bloggs’ the terms applied to ‘John Doe’ are loading in the taxonomy field. Applying new terms to ‘Fred’ shows that the terms simply accumulate.

    I can see that ACF only sets post_ids (not user_id) as the object_id when it performs wp_set_object_terms() acf/fields/taxonomy.php. I assume that this is to avoid a potential data conflict issue where a post_id and user_id are the same.

    To help avoid the conflict I have emptied my database set the autoincrement value on the wp_users table to 1000000 to reserve ids 1-1000000 for posts and 1000000+ for users.

    Can anyone suggest some code that would enable me to hook into the ACF save terms process and allow user_ids perhaps using

    wp_set_object_terms( $user_id, $term_ids, $taxonomy, false );

    Another alternative would be to create 1 custom post for each user which holds their profile data but that feels over complicated and unnecessary.