Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Advanced Custom Field Plugin to add custom fields for the users profiles and display a list of users in the frontend of site with Simple User Listing Plugin.

I need to filter a list of users by a custom search through some options: city, neighborhood and course university.

See an example of how it is being used in this screenshot:

See the screenshot of user profile displayed on the frontend

I created a form that provides the dropdown fields to allow choice of city, neighborhood and choose one of courses, but filtering does not work.

Instead of search a single user, as what is provided by the plugin, I need to display multiple users based on the search terms.

My question is: How to pass an array of values ​​to search for users and return to the list?

Here's an example of the code that I added to search by the city, the neighborhood and the course, but the search does not work. I do not know much about PHP.

if ($_GET["FormOfSearch"]){ // if search form is submitted

if(isset($_GET["nome_of_city"]))
{
  $select_city = $_GET["name_of_city"];
}else{
  $select_city = "";
}

if(isset($_GET['name_of_neighborhood']))
{
  $select_neighborhood = $_GET['name_of_neighborhood'];
}else{
  $select_neighborhood = '';
}

if(isset($_GET['name_of_course'])){
  $select_course = $_GET['name_of_course'];
}else{
  $select_course = '';
}

$list_of_id  = "SELECT user_id FROM $wpdb->usermeta WHERE (meta_value = '$select_city') AND user_id IN (SELECT user_id FROM $wpdb->usermeta WHERE (meta_value= '$select_neighborhood')) AND user_id IN (SELECT user_id FROM $wpdb->usermeta WHERE (meta_value = '$select_course'))";

// Below, the array provided by plugin, I add the list of ID searched
// Generate the query based on search field
 $args2 = array(
        'include' => '*' . $list_of_id . '*',
        'number' => $number,
            'orderby' => $orderby,
        'order' => $order
           );
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

put value of keys and check results.(use get_users function to query users)

$args=array(
    'relation'=>'AND'
);
if(isset($_GET["nome_of_city"])){
    $arg[]=array(
            'key' => 'your_key_name_1',
            'value' => $_GET["nome_of_city"]
        );
}
if(isset($_GET['name_of_neighborhood'])){
    $arg[]=array(
        'key' => 'your_key_name_2',
        'value'=>$_GET['name_of_neighborhood'],
        'compare'=>'IN'
        );
}
if(isset($_GET['name_of_course'])){
    $arg[]=array(
        'key' => 'your_key_name_3',
        'value'=> $_GET['name_of_course'],
        'compare'=>'IN'
        );
}
$users=get_users($args);
 foreach ($users as $user) {
        echo '<li>' . $user->user_email . '</li>';
    }

Important Link:

get_users()

share|improve this answer
add comment

Ravs Hello, thanks for the reply and the help. Sorry for the delay in responding.

Well, I did exactly as you stated above, but I can not spend my arrays to function of plugin according to search.

See: I created a function my_arrays that returns three arrays, each one will be created if the user select an option select.

So I return the array to the function of plugin: return array_merge( $args3, $args4, $args5 ), Using a filter: add_filter('sul_user_query_args', 'my_arrays', 10, 3);

Being that, 'sul_user_query_args' is the filter of plugin, see how is defined in the plugin:

$args = apply_filters( 'sul_user_query_args', array_merge( $args1, $args2 ) );

The paging, the role and the total users per page are defined in $ args1 and after adding my filter the rules of $args1 does not work.

The issue is: How to apply my arrays to the filter?

I appreciate any help.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.