On 'Edit Profile' page I'm trying to update user selected custom taxonomy and it works just fine but it's not updating any taxonomy which name contains "&" symbol. For example I have taxonomy called "Red & Green" and it's not updating once I try to save this "Red & Green" field. But it works if I rename the taxonomy to "Red and Green". Here is my code

function custom_user_profile_fields($user) {
<h1>Select a Category</h1>
<select name="parent_category" id="parent_category">
    global $wpdb;
    $parentCat = $wpdb->get_results( "SELECT name FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = 'project_category' AND parent = 0)" );
    foreach ( $parentCat as $cat ) { ?>
      <option value="<?php echo esc_attr( $cat->name ) ?>"<?php echo selected( $user->parent_category, $cat->name ); ?>><?php echo $cat->name; ?></option>
    <?php }
add_action('show_user_profile', 'custom_user_profile_fields');
add_action('edit_user_profile', 'custom_user_profile_fields');

function save_custom_user_profile_fields($user_id) {
    if( current_user_can('edit_user', $user_id) ) {
        update_user_meta($user_id, 'parent_category', $_POST['parent_category']);
add_action('personal_options_update', 'save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'save_custom_user_profile_fields');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.