0

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
           );

2 Answers 2

0

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()

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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