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!
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:
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.
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)