我正在使用wp_set_post_terms($post_id, $myCategory, 'sources', true );
来设置帖子的类别,使用自定义分类“来源”。我现有的一个类别是'Victoria&我从主Wordpress仪表板设置的Albert博物馆没有任何问题,但是当我使用上面的代码将该字符串作为$myCategory
传递时,它创建了一个新类别,简称为“Victoria”。我试过以几种方式逃避&符号,但这仍然没有奏效。有什么想法吗?我并不特别想强迫它'和',因为这不是他们的正确名称。
答案 0 :(得分:2)
$myCategory = str_replace('&','&',$myCategory); // And then your wp_function()...
wp_set_post_terms($post_id, $myCategory, 'sources', true );