Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 wp_set_object_terms function.

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?

share|improve this question
    
It is not entirely clear to me what you are doing but my feeling is that you are using taxonomies incorrectly. You shouldn't ever need to create a duplicate. –  s_ha_dum Mar 15 at 0:05
    
@s_ha_dum my problem is similar to this one: wordpress.stackexchange.com/questions/29023/… –  Gixty Mar 15 at 1:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.