Home › Forums › ACF PRO › User taxonomies › Reply To: User taxonomies
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.