[wp-trac] [WordPress Trac] #11361: Creating a term with the same name as a category, destroy the category.

WordPress Trac wp-trac at lists.automattic.com
Tue Dec 8 16:45:15 UTC 2009


#11361: Creating a term with the same name as a category, destroy the category.
--------------------------+-------------------------------------------------
 Reporter:  giovans       |       Owner:  filosofo
     Type:  defect (bug)  |      Status:  new     
 Priority:  normal        |   Milestone:  2.9     
Component:  Taxonomy      |     Version:  2.8.5   
 Severity:  normal        |    Keywords:          
--------------------------+-------------------------------------------------

Comment(by filosofo):

 Replying to [ticket:11361 giovans]:
 > I create a blog, and a taxonomy of categories. [[BR]]
 >
 > Let's say that one of them is Internet (with any slug you want, ie:
 internet-89).[[BR]]
 >
 > Then I add some posts over the blog, and some post is in the Internet
 category.[[BR]]
 >
 > So, now, I enter a new post, on any category, which contains the term
 "Internet" as a tag. [[BR]]
 >
 > When the tag is created, the category Internet is destroyed and replaced
 by a number.[[BR]]

 I followed these steps but was not able to reproduce the problem.  Does it
 happen when all plugins are deactivated?


 > I have tracked down the problem over the code.
 > The thing happen on wp-includes/taxonomy.php in the wp_insert_term
 procedure. Specifically on this line:[[BR]]
 >
 > if ( ! $term_id = is_term($slug) ) {[[BR]]
 >
 >
 > At this point, $slug contains the sanitized name of the term.
 > is_term returns the id of the category (Internet, remember?), instead of
 nothing, or by signalling an error. After this, the filter term_id_filter
 is called and the global_terms procedure does the damage to the
 category.[[BR]]

 I don't follow your analysis.  In this case $term_id gets set to the term
 ID for the category "Internet."  This is the expected behavior: both the
 tag "Internet" and the category "Internet" will now have the same term ID.
 It's their term_taxonomy_id that differentiates them, as distinguished in
 wp_term_taxonomy.

 This block of code, a few lines down from the one you mention, handles
 checking whether a term_taxonomy_id exists for the given taxonomy; if it
 doesn't, it creates a new one (as I said, in my tests, this works
 correctly).

 {{{
 1402         $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT
 tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN
 $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND
 t.term_id = %d", $taxonomy, $term_id ) );
 1403
 1404         if ( !empty($tt_id) )
 1405                 return array('term_id' => $term_id,
 'term_taxonomy_id' => $tt_id);
 1406
 1407         $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id',
 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
 1408         $tt_id = (int) $wpdb->insert_id;
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11361#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list