#18625 closed defect (bug) (invalid)
term_exists() doesn't make a difference between z and ẓ
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.2.1 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
I spent hours before discouvering why wp_insert_term doesn't want to create some of my categories list;
$alphabet = array ( array( 's', 'sth' ), array( 'ṣ', 'sth' ), array( 'h', 'sth' ), array( 'ḥ', 'sth' ), array( 'd', 'sth' ), array( 'ḍ', 'sth' ) ); foreach ($categories as $category ) { if( term_exists( mb_strtolower($category[0]), 'category' )) continue; else wp_insert_term( $category[0], 'category', array( 'slug' => $category[0] ) ); }
term_exists() doesn't make a difference between "normal characters" and diacritic characters.
Change History (7)
#3
@
12 years ago
I don't think it is related to MySQL collation because all my wp tables are utf8_general_ci
#4
@
12 years ago
This depends on the MySQL collation indeed. I've modified the example from the link given by xknown above, to make it more clear.
To reproduce in MySQL:
SET NAMES utf8; CREATE TABLE utf8_general_test ( c CHAR(10) ) CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE utf8_bin_test ( c CHAR(10) ) CHARACTER SET utf8 COLLATE utf8_bin; INSERT INTO utf8_general_test VALUES ('shd'), ('ṣḥḍ'); INSERT INTO utf8_bin_test VALUES ('shd'), ('ṣḥḍ');
Now
SELECT * FROM utf8_general_test WHERE c = 'ṣḥḍ';
will return both values, whereas
SELECT * FROM utf8_bin_test WHERE c = 'ṣḥḍ';
will return only one.
I've tried to put
define('DB_COLLATE', 'utf8_bin');
to wp-config.php
and reinstall WordPress (to create new tables in utf8_bin
). After that (and changing $alphabet
to $categories
), your example works fine.
Note: See
TracTickets for help on using
tickets.
It depends on the MySQL collation you are using. WordPress uses by default utf8_general_ci. See http://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html