正如OP评论中所述,在某些情况下,术语名称中可能不支持某些非ASCII字符。到replace all suspect characters with an underscore, 使用以下代码:
$categoryname = preg_replace(\'/[^a-z0-9]/i\', \'_\', strtolower($categoryname));
wp_insert_term($categoryname, "department");
至
replace all suspect characters with a dash, 使用以下代码:
$categoryname = preg_replace(\'/[^a-z0-9]/i\', \'-\', strtolower($categoryname));
wp_insert_term($categoryname, "department");
至
simply remove all suspect characters, 使用以下代码:
$categoryname = preg_replace(\'/[^a-z0-9]/i\', \'\', strtolower($categoryname));
wp_insert_term($categoryname, "department");