I’m trying to insert a term for a custom taxonomy and a custom post type in WordPress. The problem I’m running in to is that it successfully inserts a term, and at the right hierarchy level, but the term has no name. The line that inserts the term is:
$lasttermarray = wp_insert_term($categoryname, "department", array( "parent" => $parentcategory ) );
I’ve checked to make sure that both $categoryname and $parentcategory are set to the right values. Like I said, the term is being inserted, just with a blank name. The slug of the blank term is being set to the ID of the new term.
Is there any reason why the function would not be reading the name variable and causing it to do this? Thanks for your help.
As noted in the OP’s comments, some non-ASCII characters may not be supported in term names under certain conditions. To replace all suspect characters with an underscore, use the following code:
To replace all suspect characters with a dash, use the following code:
To simply remove all suspect characters, use the following code: