• Resolved Joseneas

    (@enoquenroll)


    Hello,

    I liked this plugin and I’m doing a great job with it. I am using the Advanced Custom Field Plugin to add custom fields for the users profiles and display in the frontend with Simple User Listing Plugin. I tested many plugins, but the Simple User Listing was the best of all. Congratulations to the developer! ??

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

    https://i.imgur.com/krI5oEE.png

    I’m using in my university to list curriculum of students from different courses.

    However, I need to add the option to filter user by city, neighborhood and undergraduate course. 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?

    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'))";
    
    // Generate the query based on search field
     $args2 = array(
    	    'include' => '*' . $list_of_id . '*',
    	    'number' => $number,
                'orderby' => $orderby,
    	    'order' => $order
               );

    Can anyone help me?

    I appreciate any help.

    https://www.ads-software.com/extend/plugins/simple-user-listing/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    I am glad you like the plugin. The best I can do for you right now is to suggest that you read up on WP_User_Query to know its limitations.

    There are also several tutorials on using the WP_User_Query class. This one might be pertitent:

    https://tommcfarlin.com/get-user-by-meta-data/

    If there is a hook/filter you discover you need added to the SUL plugin to avoid hacking it directly I’d be happy to add that. I am just not in a very aggressive development, nor support mode for this plugin as I am focused on other things.

    Good luck.

    Thread Starter Joseneas

    (@enoquenroll)

    Hello helgatheviking,

    Thank you for the reply.

    Okay, I’ll follow your tip. The tutorial looks good.

    Yes, I use hooks because updates Plugin.

    One tip, could include(future update) paging links Example: First, Previous, 2, 3, 4, 5, Next, Last.

    which is interesting for large numbers of users.

    Thank you.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Sorry I can’t really help more, but again, let me know if there is a hook you need that I can add. The development is hosted on github:
    https://github.com/helgatheviking/simple-user-listing

    As far as pagination, that’s one of the templates you can override, so in theory it should be possible. If you wanted to work on making it work with WP Pagenavi, I’d be interested to include that in an update.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Additionally, I will point out that I already have a filter for the WP_User_Query arguments, which might be helpful

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

    (@enoquenroll)

    Hi, hello helgatheviking,

    Sorry for the delay in responding.

    Well, support for page-navi would be nice, I’ll be grateful if you add.

    On the filter, see how I’m using:

    I created a function ‘custom_search’ with a search form with 3 dropdowns and one submit button. I added the function in functions file of my theme.

    I used the hook: add_action(‘simple_user_listing_before_loop’, ‘custom_search’) to add my search form below on the form provided by the Plugin, so far so good.

    I created another function with three arrays with return meta_keys according to options selected by dropdows the search form.

    I tried several ways but could not get the filter search function with my arrays $args3, $args4, args5.

    For this, I created another function that returns three custom_array: return array_merge($args3, $args4, $args5)

    Each array will be created if case the user select an option from each select on the form search.

    At the end I added the filter: add_filter(‘sul_user_query_args’, ‘my_arrays’, 10, 3);.

    What happens is that paging doesn’t work and neither limit users per page. ??

    My question is: what is the correct way to add my arrays to filter the list of users?

    I will be very grateful if you can give help me. ??

    Thread Starter Joseneas

    (@enoquenroll)

    Problem solved. I was returning an array with options of a field, same when the ‘meta_value’ and ‘meta_key’ used for term of search not was filled.

    Congratulations for the plugin.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Glad you got it solved. Would you mind posting your filter code in case any one else has the same question?

    Thread Starter Joseneas

    (@enoquenroll)

    Yes! No problems.

    Well, I have another problem with two dynamic dropdowns that list the neighborhood according to the city selected. But that has nothing to do with SUL.

    I’ll post the code when the error is solved.

    Thank you.

    Thread Starter Joseneas

    (@enoquenroll)

    Hi, Hello helgatheviking. ??

    Sorry for the delay in return the code.

    I posted the code in Pastbin and you can access this link: https://pastebin.com/ASX2VJcZ

    Well, I hope you can understand, I tried translate for English for you that understand.

    Basically it is this:

    The file is used for generate a custom list of profiles using a search filter that show custom informations of users (with custom fields created with Advanced Custom Fields Plugin).

    This file add a custom form with 4 select option fields for to allow choose the list of users by city, neighborhood and course university. In my case (my university), each course is attached a single modality, then I get the modality for generating a dynamic list of courses according to the modality selected. For this I used jquery ajax (conditional logic) into another javascript file.

    I add another file that display the list of profiles, showing a set of information of each user. The informations are: city, neighborhood, postcode, email, telephone, university course, course period in which the user is studying, age, additional courses conducted by the user and other information.

    I could not add a hook to display the list of profiles. I created a function and had to call it in the file content-author.php.

    See: (I commented a piece of code and just include my function. This was the only file that I edited)

    <div id="user-<?php echo $user->ID; ?>" class="author-block">
    
    <?php display_info_profiles(); ?>
    <!--
    	<?php echo get_avatar( $user->ID, 90 ); ?>
    	<h2><a href="<?php echo get_author_posts_url($user->ID); ?>"><?php echo $user_info->display_name; ?></a> - <?php printf( _n( '%s post', '%s posts', $num_posts, 'simple-user-listing' ), $num_posts ); ?>
    	</h2>
    	<p><?php echo $user_info->description; ?></p>
    
    	<p><a href="<?php echo get_author_posts_url($user->ID); ?> ">Read <?php echo $user_info->display_name; ?> posts</a></p>
    -->
    </div>

    In a future update, you could add a filter so that I can print my list without having to edit the file content-author.php?

    Although… I still can not paginate the list of users after filtering. Do you have any tips on how to do pagination the custom search?

    Note that in the array’s I added options: $number, $offset, $paged, but it did not work.

    Well, I live in Brazil, sorry for the bad English.

    Tahnk you.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    You should not be displaying a list in content-author.php. If your query returns any users, then each user in the list is displayed by content-author.php. content-author.php is a single user, not a list of users.

    If $number, $offset, $paged are all still not working, then you must be filtering the query vars incorrectly.

    No worries on the English. I tried to learn Portugeuse and only got to be able to say “Eu sou americano. Eu n?o falo portugeuse”

    Thread Starter Joseneas

    (@enoquenroll)

    Ok. Thanks for the reply.

    Well, I confess I do not quite understand about the pagination. But, when I have many users that push the limit of users per page, the pagination links ‘Next’ and ‘Previous’ appears below, but they do not get the search terms.

    Example: when I select a option eg: City and I click for search, in url address are as follows: ‘https://localhost/direc.ifba/curriculo/?city=Salvador&neighborhood=&course=&#8217;

    Salvador is the city, the neighborhood and the course were blank. Ok! the result is the expected because 3 users are listed(that is the limit of user per page), and the links of pagination appears below. But when I click on the ‘Next’ the search term does not sent with pagination.

    The ‘Next’ link looks like this: ‘https://localhost/direc.ifba/curriculo/page/2/&#8217; without considering the search term it should be like this: ‘https://localhost/direc.ifba/curriculo/?city=Salvador&neighborhood=&course=/page/2/&#8217;.

    See, I just add the file that prints the fields in Pastbin.

    You can access this link: https://pastebin.com/K9n5ruaj

    It is a little big, and is in Portuguese. ??

    Plugin Author HelgaTheViking

    (@helgatheviking)

    I still suspect the query vars aren’t working properly… either on your side, or on my side… of perhaps both.

    I see this in your code:

    I tried using the hook down but only prints a single user per page.

    That must mean the query isn’t right, b/c the loop should work. I am pretty busy at the moment so I can’t really look into it.

    Thread Starter Joseneas

    (@enoquenroll)

    All right, ok. Thanks for the tip helgatheviking.

    I’ll review the code and see where the error about pagination. I’ll post the snippet of my arrays(of my function) in another forum WordPress, can be that some user already has a similar problem.

    Thank you for the replies. ??

    Thread Starter Joseneas

    (@enoquenroll)

    Hi,

    Sorry for the inconvenience, I did some tests with other plugins of users as Members List Plugin and UPME (another premium plugin sold on CodeCanyon) which is very good, but both have features that are not for me.

    Well, I realized that the SUL Plugin does not make pagination when search results return many results.

    So… I do not want to modify the plugin code. You can fix this?

    Support for page-navi would be great.

    I would like to gratify their work.

    Could you pass me your email?

    Plugin Author HelgaTheViking

    (@helgatheviking)

    I don’t think pagenavi supports user queries yet, but I could be wrong.

    I guess I never had enough users to be able to test that on. I’ll have to look into that, but I am a little swamped with client work at the moment. If you have the fix, or find it before I get around to this, definitely share and I’ll include it in the next update.

    I’d rather not post my email here, but you can email me via my website:
    https://kathyisawesome.com/contact

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Add a Search Custom Users by Several Options’ is closed to new replies.