You could use meta_query, it can handle arrays and strings.
So something like this
// get location meta, will be easier to determine what is the type of value
$location = get_post_meta(get_the_ID(), 'Location',true);
$posts = get_posts([
'posts_per_page' => 10,
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'date',
'meta_query' => [
[
'key' => 'Location',
'value' => $location,
'compare' => is_array($location) ? 'IN' : '='
]
]
]);
Now you can do all the rest as usual.
So what we did here is
- get and assing
Locationmeta to a variable,$location - add that variable as value in the
meta_query - based on the type of value of the variable we create the compare logic
By the way, get_permalink() and the_title() will output/return the link and title of the current post, NOT the looped post.
When using get_posts() they are available as object properties, so like this
foreach($posts as $post) {
$post->post_title; // the post title
get_permalink($post->ID) // the looped post permalink, we need to pass the looped post ID as argument to "tell" get_permalink what link we need
}