Title: delete_user_meta problem matching substring
Last modified: August 21, 2016

---

# delete_user_meta problem matching substring

 *  Resolved [Jose Llanos](https://wordpress.org/support/users/latinunit/)
 * (@latinunit)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/)
 * In the database I have the following user meta;
 * > [View post on imgur.com](https://imgur.com/MiL5G)
 * I use the following function to delete the user meta
 *  `delete_user_meta( $user_id, 'dismissed_wp_pointers', 'lu_ban_settings_pointer');`
 * Where `lu_ban_settings_pointer` is the meta value I want to match, the problem
   here is that the data contains comma separated values, so a full string match
   will fail
 * > wp330_toolbar,wp330_saving_widgets,wp340_choose_image_from_library,wp340_customize_current_theme_link,
   > wp350_media,wp360_revisions,wp360_locks,lu_ban_settings_pointer
 * The problem is that the function only deletes the meta value as long as the full
   string matches, meaning that I have to go through the array and match the substring.
 * What would be the best way to achieve this?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [Jose Llanos](https://wordpress.org/support/users/latinunit/)
 * (@latinunit)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4216792)
 * **Update**
 * A friend achieved to perform this operation by doing the following;
 *     ```
       $remove_value = 'lu_ban_settings_pointer';
           $meta_data = get_user_meta( $user_id->ID, 'dismissed_wp_pointers' );
           if (isset($meta_data['0'])) {
               //                           //at end (or mid)  //at beg (or mid)  //failsafe
               $new_val = str_replace(array(','.$remove_value, $remove_value.',', $remove_value), '', $meta_data['0'])
               update_user_meta( $user_id->ID, 'dismissed_wp_pointers', $new_val);
           }//end isset meta_data 0
       ```
   
 * However, I think that there should be an easier way of achieving this, why would
   WordPress make it so difficult to delete a comma separated value in a user’s 
   meta data.?
 *  Thread Starter [Jose Llanos](https://wordpress.org/support/users/latinunit/)
 * (@latinunit)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4216892)
 * Can anyone help please, it is rather urgent
 *  Thread Starter [Jose Llanos](https://wordpress.org/support/users/latinunit/)
 * (@latinunit)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4216910)
 * I’ve solved it. thanks
 *  [Devin Walker](https://wordpress.org/support/users/dlocc/)
 * (@dlocc)
 * [12 years ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4217120)
 * Yeah this is pretty difficult. Ugh.
 *  [Devin Walker](https://wordpress.org/support/users/dlocc/)
 * (@dlocc)
 * [12 years ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4217121)
 * This is how I’m deleting the dismissed_wp_pointers from the array:
 *     ```
       //Display
       		$dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
   
       		// Check if our pointer is among dismissed ones and delete that mofo
       		if ( in_array( 'gmb_welcome_pointer', $dismissed_pointers ) ) {
       			$key = array_search( 'gmb_welcome_pointer', $dismissed_pointers );
       			delete_user_meta( $user_id, 'dismissed_wp_pointers', $key['gmb_welcome_pointer'] );
       		}
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘delete_user_meta problem matching substring’ is closed to new replies.

 * 5 replies
 * 2 participants
 * Last reply from: [Devin Walker](https://wordpress.org/support/users/dlocc/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/delete_user_meta-problem-matching-substring/#post-4217121)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
