Make WordPress Core

Opened 9 years ago

Closed 7 years ago

Last modified 7 years ago

#18625 closed defect (bug) (invalid)

term_exists() doesn't make a difference between z and ẓ

Reported by: abdessamad idrissi Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Taxonomy Keywords:
Focuses: Cc:


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' )) 
		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)

#1 @xknown
9 years ago

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

#2 @xknown
9 years ago

Related to a collation issue #18210

#3 @abdessamad idrissi
9 years ago

I don't think it is related to MySQL collation because all my wp tables are utf8_general_ci

#4 @SergeyBiryukov
9 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:

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'), ('ṣḥḍ');


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.

Last edited 9 years ago by SergeyBiryukov (previous) (diff)

#5 @ericmann
7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Based on the above comments, this appears to be a non-issue.

#6 @dd32
7 years ago

  • Milestone Awaiting Review deleted

#7 @SergeyBiryukov
7 years ago

  • Resolution changed from worksforme to invalid
Note: See TracTickets for help on using tickets.