I'd like to send email notifications when new posts are saved. But users can select post categories they want to subscribe to. Available plugins are no solution to me – I really need my own code base. Even though I am fairly new to WP there is no problem with all that … but I don't know how to connect custom taxonomies to users.

Is it possible to list all categories on the user profile page (checkboxes) and save theme in the usermeta table? Or do you mean it is better to put all the subscriptions into a new table and use a third pivot table to connect taxonomies and users?

Or another solution? Any ideas are appreciated :-) Many thanks!

2 Answers 2


I came across a tutorial about 'Custom User Taxonomies in WordPress' and there is a plugin based on that 'User Taxonomies' but these are for creating taxonomies for Users. Have a read thought the tutorial it might help.

I think what you're talking about is to associating posts' taxonomies with users. I think you need to use something like wp_set_object_terms (Codex) to create a relationship between the user and taxonomy term, so you'll have something like:

wp_set_object_terms( $object_id, $terms, $taxonomy, $append )
  • $object_id - will be your user_id
  • $terms - corresponding terms
  • $taxonomy - corresponding taxonomy
  • $append - false. Every time a user saves her/his choice of taxonomy terms to subscribe for, you'd need to go through them and add them again (in case something has been un-ticked that was ticked before).

You would need to make sure to clean up the DB whenever a user/taxonomy/taxonomy term is deleted, so you should clean up the relation of object and taxonomy terms you created previously. Use wp_delete_object_term_relationships (Codex).

I hope that points you in the right direction.

  • Agree this is the best way. Note the second argument to register_taxonomy can be an array, so you can put post and user together and they will both refer to an identical taxonomy. Also note that this will cause your Post Count column on the tax page to be inaccurate, though you could quite easily fix it by adapting the tutorial code.
    – djb
    Feb 26, 2014 at 21:35
  • That is exactly what I was looking for! Many thanks. I just had a brief look on the code and it will help definitely.
    – suntrop
    Feb 27, 2014 at 18:27
  • Curious if this would support users "connected"/associated with multiple categories/taxonomies.
    – lcm
    Mar 27, 2021 at 8:00

I was/am using the user taxonomy snippet as well.

However, I highly recommend not to mix users and posts in one taxonomy. Meaning registering a taxonomy for users AND posts.

The wp_term_relationships table just stores an object_id. Once there's a post and a user with the same ID, everything gets messed up because then, the term is assigned to both, user and post with that ID.

My solution was to register two taxonomies, one for each type (post,user), and to keep the term pool synchronous by programmatically add/delete/alter terms in both taxonomies. (Using these hooks: created_term, pre_delete_term, edited_term)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.