WordPress, fetching users with an exact match in a string of comma separated values in user_meta

I have data saved in user_meta -> areapref field. It is basically a string of comma delimited post IDs (e.g. 2, 37, 200, 300 etc.)

I need to check if the user has a particular ID in this field. If so… do stuff.

I can check if an ID is in areapref using LIKE. But I believe this has an issue. If one location is ID=10, and another is ID=100 – both will match with 1, or 10? Or am I misunderstanding LIKE. I fear CONTAIN would have the same issue.

I need to know how to get a list of users who have an ‘exact match’ within the areapref string? So search for ID 2, will return only 2, NOT 22, or 20, 200 etc. I’ve spent hours going through stackexchange/overflow/wp codex and cannot find an answer… though I am dense!

Here’s enough code I hope to show what I’m currently doing… any ideas greatly appreciated.

function ds_notify_new_event( $  post_ID ){ $  url = get_permalink( $  post_ID ); $  event = get_the_title( $  post_ID ); $  localeID = get_post_field( 'location_id', $  post_ID); global $  wpdb; $  locale = $  wpdb->get_var( $  wpdb->prepare( " SELECT post_id FROM {$  wpdb->prefix}em_locations WHERE ID = %d ", $  localeID ) );  $  args = array(         'role'    => 'subscriber',         'meta_query' => array(                 array( 'key' => 'areapref', 'value' => $  locale, 'compare' => 'LIKE' ),                 // just checks usr is ok with email                 array( 'key' => 'notify', 'value' => 'yes', 'compare' => '=' )              ),         'fields' => array( 'display_name', 'user_email' )     ); // retrieve users to notify about the new post $  users = get_users( $  args ); 

// do stuff with users