I'm trying to get values from my usermeta table depending on a certain provence.
I live in the Netherlands. We have 12 provences here and I want to select all users who live in a certain provence. So I added a field to the user database that is named 'provincies'. A button with a value <a href="results.php?provincie=provencename"
tells me who to select based upon the value from the url.
This isn't difficult. The problem is that users can have multiple provences.
So the meta_key provincie fields hold the meta_value friesland','groningen','drenthe'
So now I need to search if the added value from the url is in the database meta_value.
$provincie_array = "friesland','groningen','drenthe";
$query = "SELECT *
FROM $wpdb->usermeta
WHERE meta_key='provincie'
AND meta_value IN ('".$provincie_array."')";
I think this is right. However PHP and MySql beg to differ.
Can anybody see what I'm missing here?
-EDIT-
$provincie = $_GET['provincie'];
global $wpdb;
//$query = "SELECT * FROM $wpdb->usermeta WHERE meta_key='provincie' AND meta_value IN ('".$provincie_array."')";
$provincie_array = array('friesland','groningen','drenthe','noordholland','flevoland','overijssel','zuidholland','utrecht','gelderland','zeeland','noordbrabant','limburg');
$provincie_check = '';
foreach ($provincie_array as $value) {
$provincie_check[]="`meta_value` LIKE '%[{$value}]%'";
}
$query = "SELECT *
FROM $wpdb->usermeta
WHERE meta_key='provincie'
AND ( ".implode(' OR ',$provincie_check)." )";
$personen = $wpdb->get_results($query);
INfunction