Database – How do I clear a specific meta_value for all users in PHP

I am able to successfully clear the meta_value for a specific meta_key. The problem is that a new meta_key will be created for all users in the database. I don’t want all users to maintain a meta_key in the database unless it already exists.

I guess maybe if I set guest_list_venue_names as a variable and check if it exists, I can use an IF statement? I am new to PHP so any insight would be helpful.

$wp_user_query = new WP_User_Query(array('role' => 'Subscriber'));

$users = $wp_user_query->get_results();

if (!empty($users)) {


    foreach ($users as $user)
    {
        update_user_meta( $user->id, 'guest_list_venue', ''); 
        update_user_meta( $user->id, 'guest_list_venue_names', ''); 
    }
}

Leave a Comment