Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#38508 closed defect (bug) (invalid)

wp_insert_term and [term_taxonomy_id] => 0 )

Reported by: staticweb's profile staticweb Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Hello,

I use WordPress version: 4.6.1 and WooCommerce version 2.6.6 with XAMPP/WIN7.

I want to import categories from osCommerce and i have some categories with [term_taxonomy_id] => 0 and no record in wp_term_taxonomy after wp_insert_term.

I think this is a bug. If no record in wp_term_taxonomy is created a error should come.

$parent_term = term_exists($line["parent_categories_name"], 'product_cat');
wp_insert_term(
  $line["categories_name"],
  'product_cat',
  array(
    'description'=> $line["categories_description"],
    'slug' => $line["categories_slug"],
    'parent'=> $parent_term['term_id']
  )
);

Change History (4)

#1 @boonebgorges
7 years ago

  • Keywords reporter-feedback added

@staticweb Welcome to WordPress Trac! Thanks for the ticket.

term_taxonomy_id should never equal 0. It's an autoincrement field.

What tool are you using to import osCommerce items into WooCommerce? It's possible that the tool is doing direct database imports.

#2 @staticweb
7 years ago

@boonebgorges:

What tool are you using to import osCommerce items into WooCommerce? It's possible that the tool is doing direct database imports.

I've done a sql dump with phpmyadmin and make sql selects with a PHP Script.

I found the reason for the error.

The osCommerce data are in latin1. I've done the sql dump with utf-8 and the local osCommerce database is in utf-8 also.

4 category descriptions have a special content with line break after german umlaut ä. I deleted the line breaks and it works.

The deleted HexCode ist d0a0d0a0 .

In lines 2366/2367 of taxonomy.php the insert not working with the special characters.

$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
$tt_id = (int) $wpdb->insert_id;

Description content must better sanitize for insert with success.

term_taxonomy_id should never equal 0. It's an autoincrement field.

The insert don't work!

#5 @boonebgorges
5 years ago

  • Keywords bulk-reopened added
  • Resolution set to invalid
  • Status changed from new to closed

Re-closing this ticket, as it appears to be an issue with database collation and the script used for import.

#6 @desrosj
5 years ago

  • Keywords reporter-feedback bulk-reopened removed
Note: See TracTickets for help on using tickets.