Title: Duplicate Category Names
Last modified: August 19, 2016

---

# Duplicate Category Names

 *  Resolved [laqrhead](https://wordpress.org/support/users/laqrhead/)
 * (@laqrhead)
 * [17 years ago](https://wordpress.org/support/topic/duplicate-category-names/)
 * I was having some issues adding sub-categories that had duplicate names, but 
   unique slugs. I don’t know if this is a bug or a feature, but since the slug 
   is the unique key, it doesn’t make sense to me why you couldn’t be able to have
   duplicate names if the slug is unique. Anyways, here is a hack, not a plugin,
   so you’ll need to fix it again if you update wordpress.
 * To allow duplicate names, but keep unique slugs, find the following code (lines
   312-318) in wp-admin/admin-ajax.php:
 *     ```
       if ( category_exists( trim( $_POST['cat_name'] ) ) ) {
       		$x = new WP_Ajax_Response( array(
       			'what' => 'cat',
       			'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ),
       		) );
       		$x->send();
       	}
       ```
   
 * Replace with this code:
 *     ```
       if ( category_exists( trim( $_POST['category_nicename'] ) ) ) {
       		$x = new WP_Ajax_Response( array(
       			'what' => 'cat',
       			'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'category_nicename' ) ),
       		) );
       		$x->send();
       	}
       ```
   
 * What you are doing is changing the instances of “cat_name” with “category_nicename”,
   This has it check the slug for uniqueness, and not the name.
 * I tested briefly for myself and it seems to be working.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [nicomarie2009](https://wordpress.org/support/users/nicomarie2009/)
 * (@nicomarie2009)
 * [17 years ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087529)
 * hey, i just made my user in the forum for thanks you, it works and you save me.
   
   So thank you very much
 *  [Pierre_02](https://wordpress.org/support/users/pierre_02/)
 * (@pierre_02)
 * [17 years ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087579)
 * and by replacing :
 *     ```
       $cat_id = wp_create_category( $cat_name, $parent );
       ```
   
 * by :
 *     ```
       $cat_id = wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
       ```
   
 * Line 241 in the same file you will be able to add categories on the fly in the“
   post-new” part 😉
 * Amicably,
 * Pierre.
 *  [britanik](https://wordpress.org/support/users/britanik/)
 * (@britanik)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087587)
 * Can you help with the same issue but regarding to POST names instead of CAT names?
 *  [zuz3l](https://wordpress.org/support/users/zuz3l/)
 * (@zuz3l)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087629)
 * Is it possible to hack WP so that slugs aren’t unique? I use slugs in a quite
   strange way. I display slugs as prices on a menu card for a bar.
    Maybe I should
   find another way.
 *  [lcorri](https://wordpress.org/support/users/lcorri/)
 * (@lcorri)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087639)
 * THANK YOU, THANK YOU, THANK YOU!!! This is the only place on the whole internet
   that there seems to be a fix!! Worked for me 🙂
 *  [javierfaus](https://wordpress.org/support/users/javierfaus/)
 * (@javierfaus)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087642)
 * That worked out like a charm in WP 2.6.3!!
 * Thanks indeed.
 * javier.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Duplicate Category Names’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [catgories](https://wordpress.org/support/topic-tag/catgories/)
 * [duplicate](https://wordpress.org/support/topic-tag/duplicate/)

 * 6 replies
 * 7 participants
 * Last reply from: [javierfaus](https://wordpress.org/support/users/javierfaus/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/duplicate-category-names/#post-1087642)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
