使用wp_get_post_terms在类别名称中插入&符失败

时间:2013-11-08 10:42:53

标签: php wordpress categories

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

1 个答案:

答案 0 :(得分:2)

$myCategory = str_replace('&','&',$myCategory); // And then your wp_function()...
wp_set_post_terms($post_id, $myCategory, 'sources', true );