Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#11361 closed defect (bug) (invalid)

Creating a term with the same name as a category, destroy the category.

Reported by: giovans's profile giovans Owned by: filosofo's profile filosofo
Milestone: Priority: normal
Severity: normal Version: 2.8.5
Component: Taxonomy Keywords:
Focuses: Cc:

Description

I create a blog, and a taxonomy of categories.

Let's say that one of them is Internet (with any slug you want, ie: internet-89).

Then I add some posts over the blog, and some post is in the Internet category.

So, now, I enter a new post, on any category, which contains the term "Internet" as a tag.

When the tag is created, the category Internet is destroyed and replaced by a number.

---

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:

if ( ! $term_id = is_term($slug) ) {

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.

In my humble opinion. the is_term procedure, should be called as:
is_term($slug,$taxonomy) thus separating "category" and "post_tags".

Greetings and thanks for the support.

Giovans

Change History (4)

#1 @Denis-de-Bernardy
15 years ago

  • Component changed from General to Taxonomy
  • Milestone changed from Unassigned to 2.9
  • Owner set to filosofo

blocking?

#2 in reply to: ↑ description @filosofo
15 years ago

Replying to giovans:

I create a blog, and a taxonomy of categories.

Let's say that one of them is Internet (with any slug you want, ie: internet-89).

Then I add some posts over the blog, and some post is in the Internet category.

So, now, I enter a new post, on any category, which contains the term "Internet" as a tag.

When the tag is created, the category Internet is destroyed and replaced by a number.

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:

if ( ! $term_id = is_term($slug) ) {

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.

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;           

#3 @giovans
15 years ago

I am so sorry, filosofo. And so stupid, sometimes. This is one of them.
You are right. My problem is with wpmu, not vanilla wordpress.
Please accept my apologies :-(

Greetings,
Giovans

#4 @filosofo
15 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.