Connect Users and Taxonomies

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.

Leave a Comment