This is your problem:
$follow_ids = $wpdb->get_results( "SELECT meta_value FROM brilli_usermeta WHERE user_id = ".$user_id );
No meta key is specified, and it’s a raw SQL query, which means all user meta values are returned, even those that aren’t relevant. You need to specify a key
But why bother with a direct query, when a cached API is available, thats much easier to use, much safer, and much faster?
$follow_ids = get_user_meta( $user_id, 'follow_ids', false );
foreach( $follow_ids as $id ) {
// etc ...
}
Where 'follow_ids'
is to be replaced with the meta key you used to store your followers IDs in
Additional notes:
- You should be using taxonomy terms or this not user meta, especially if you ever want to show a list of users who follow a person
- Never use
query_posts
, there is no valid or good reason to use it. Usepre_get_posts
to modify or replace the main query, or useWP_Query
to add new queries - Never use raw SQL to fetch data from the DB stored in WP tables. There are functions for doing that, and they’re much faster than any SQL you can write. And safer too, your query had no escaping or preparation applied