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.
- The topic ‘Duplicate Category Names’ is closed to new replies.