iuwan
iuwan

Reputation: 43

WordPress - custom taxonomy values for each user?

Is it possible to have a taxonomy which displays different values for each user? A quick example on what I have in mind:
Let's call our taxonomy: "Life". User John Doe adds a post, creates the "Music" and "Movies" to the "Life" taxonomy.
Then Jane Doe adds a new post, and the "Life" taxonomy is empty for her as long as she adds "Televison". She does not see "Music" and "Movies", if she does not add one.
When John Doe goes back to his post, he can't see the "televison" Jane added.

I'm very new to WordPress, so I'm not really sure if it is possible to achieve something like this.
If it wouldn't possible, could you suggest some alternatives? It would be extremely important that users must not see each other's terms, just their own.

Upvotes: 0

Views: 314

Answers (2)

itoctopus
itoctopus

Reputation: 4261

WordPress, by default, does not store the ID of the user who created the taxonomy. As such, you cannot really do the above with a core Wordpress instance. Additionally, there are no plugins (that I know of) that can do that for you.

On the bright side, you can add this support yourself. Here's how:

  • You modify the term_relationships table to have a field (maybe called userid) that contains the ID of the user who created the taxonomy. This can be done in phpMyAdmin.
  • You will then need to open the file wp-includes/taxonomy.php and change the following line:

    $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) );
    

    to:

    $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id, 'userid' =>  get_current_user_id()) );
    
  • Finally, you will need to modify your template file called the the_tags function with an alternative function (that is created by you) that will take into account the current user id.

(Note that if get_current_user_id() doesn't work, then you need to find an alternative method to get the user id.)

Upvotes: 2

Irina
Irina

Reputation: 11

If I understand well what you need, maybe this plugin can solve it: https://wordpress.org/plugins/user-specific-content/ or look for something similar in WP repository.

Upvotes: 1

Related Questions