I just encountered a problem and realized that all tags must be globally unique.
Here is what just happened to me:
I created a taxonomy called
writer and added each author and collaborator to the post they have written or/and collaborated to. For this, I was getting
post id as the $object_id and
user nicename as the $term for the
After filling up my new taxonomy with the writters, I wanted to display a list of posts using WP_Query and tax_query. The arguments for the tax_query would be as follows:
'tax_query' => array( array( 'taxonomy' => 'writer', 'field' => 'slug', 'terms' => $array_of_nicenames ) )
So each item in the array would be matched against the taxonomy slug.
Everything was working fine until I hit and already created slug. Thus, the writer slug would read
user_nicename-2 instead of
user_nicename. The post made by this user would not be displayed on my list.
I hope I am making myself clear; otherwise, ask me to clearify anything.
I was thinking about using the user id instead of the user nicename; however, eventually I would come up with the same problem. For example, I could have a tag called 2003 and a user with the same id.
A possible solution I came up with but I would like to avoid is this one:
For each new user, create a meta tag that would include the user nicename attached to a preffix like this
uniquepreffix-user_nicename, thus incrementing my chances to have a really unique username/slug for later use.
Is there any other way I can accomplish what I want without encountering this problem? Can I use tax_query by name instead of slug?