Inserting an ampersand in a category name using wp_get_post_terms fails

I am using wp_set_post_terms($post_id, $myCategory, 'sources', true ); to set the category of a post, using the custom taxonomy ‘sources’. One of my existing categories is ‘Victoria & Albert Museum’ which I have set up from the main WordPress dashboard without any problems, but when I pass that string as $myCategory using the code above it creates a new category simply as ‘Victoria’. I have tried escaping the ampersand in several ways but this still hasn’t worked. Any thoughts? I don’t especially want to force it to ‘and’ as that’s not their correct name.

Related posts

Leave a Reply

1 comment

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