<?php
// ALWAYS sanitize user input!
$poblacion = sanitize_text_field( $_GET['poblacion'] );
$trabajo = sanitize_text_field( $_GET['trabajo'] );
$usuarios = get_users(
array(
'role' => 'empresa-BBDD',
'order_by' => 'nicename',
'order' => 'ASC',
'meta_query' => array( // search for user meta data
'relation' => 'AND',
array(
'key' => 'poblacion',
'value' => $poblacion,
'compare' => 'LIKE' // partial comparison
),
array(
'key' => 'trabajo',
'value' => $trabajo,
'compare' => 'LIKE' // partial comparison
)
)
)
);
'relation' => 'AND'
is used to find users with both keys matching. Otherwise, use ‘OR’.
'compare' => 'LIKE'
is the same as '%LIKE%'
in MySQL, which is to say using ‘wildcards’ on both ends. Search for ’34’ will give you ’1234‘, ‘2345′ and ‘34567′.
Note! The code was not tested.