WordPress ultimate member edit search filters for custom fields

Is there any way to edit search filters on WordPress plugin ultimate member? As I know standard filters include the only field which is selected from backend and search user must match all specified fields (logical and). I want some way to edit search and add more functions (or, less than, more than) for some fields. So far I haven’t found out how the search is proposed if is based on the global $wpdb variable or some other way.

Related posts

1 comment

  1. I am using Ajax in my example to search for users based on conditions, and here I use country, The list of cities is already defined in an array, and I summon it here in loop.

    <?php /*Template Name: Users* /?> 
    
    
    <div class="row">
            <div class="col mb-2">
                <h5 class="mb-3" >
                    <?php echo __('Advanced','booksinfo') ?>
                </h5>
                
                <input class="form-control mb-2" placeholder="<?php echo __('User name','booksinfo') ?>" name="username" id="username" onkeyup="users_fetch()"  />
                                
                <select name="usercountry" id="usercountry" class="form-control" onchange="users_fetch()">
                    <option value="all" ><?php echo __('All countries','booksinfo') ?></option>
                    <?php
                        $user_country = get_user_meta( $current_user->ID, 'user_registration_user_country', true );
    
    
                            foreach ($countrys_list as $country ) {
                                
                                echo "<option value="$country">".esc_html__($country,'booksinfo') ."</option>";
                            
                        }
                        ?>
                </select>
                
            </div>
            <div class="col-md-9">
                <div class="row" id="users_list_div">
                    <script>
                        jQuery.ajax({
                            url: '<?php echo admin_url('admin-ajax.php'); ?>',
                            type: 'post',
                            data: { action: 'users_data_fetch'},
                            success: function(data) {
                                jQuery('#users_list_div').html( data );
                            }
                        });
                    </script>
                </div>
            </div>
            </div>
    

    Well, now that we have completed a form to search for users by name and city, we are preparing the code in functions.php

    // add the ajax fetch js
    function users_ajax_fetch() {
    ?>
    <script type="text/javascript">
    function users_fetch(){
        jQuery.ajax({
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            type: 'post',
            data: { action: 'users_data_fetch', username: jQuery('#username').val(), usercountry: jQuery('#usercountry').val() },
            success: function(data) {
                jQuery('#users_list_div').html( data );
            }
        });
    
    }
    </script>
    
    <?php
    }
    add_action( 'wp_footer', 'users_ajax_fetch' );
    
    function users_data_fetch(){
        if( $_POST['username']){
            if($_POST['usercountry'] != 'all'){
                $user_country = $_POST['usercountry'];
                $compare_country = '=';
            }else{
                $user_country = '';
                $compare_country = 'LIKE';
            }
            
            $args = array(
                        'orderby' => 'first_name',
                        'order'   => 'ASC',
                        'meta_query'    => array(
                            array(
                            'key'      =>  'user_registration_user_country',
                            'value'    =>  $user_country,
                            'compare'      => $compare_country,
                            ),
                            array(
                            'key'      =>  'nickname',
                            'value'    =>  $_POST['username'],
                            'compare'      => 'LIKE',
                            )
                        )
    
                    );
        //}
    $users = get_users( $args );
    $users_result = $users[0]->ID;
    if($users_result){
    foreach ( $users as $user ) {
    $user_pic = get_user_meta( $user->ID, 'profilepicture', true );
    $user_type = get_user_meta( $user->ID, 'user_registration_user_type', true );
    
    ?>
        <div class="col-xl-4 col-md-6 col-sm-6 text-center mb-3">
            <div class="col border pt-2">
                <a href="<?php echo get_site_url() .'/author/'. $user->user_nicename ?>" >
                    <? if($user_pic){ ?>
                        <div class="" style="background:url('<?php echo $user_pic ?>');width:110px;height:110px;margin: auto;background-size: cover;background-position: center;    border-radius: 100px;" ></div>
                    <?php
                    }else{
                            echo '<img src="' . get_template_directory_uri() . '/images/user.svg" style="border-radius:100px;width:110px;height:110px;margin">';
                            //echo get_avatar( $curauth->user_email , '120 '); 
                    }
                </a>
                <div class="mt-1 mb-3">
                    <?php echo $user->display_name; ?>
                </div>
                <div class="row">
                    <a class="col text-center btn btn-success" href="<?php echo get_site_url() .'/author/'. $user->user_nicename ?>" >
                        <?php echo __('View prfile','booksinfo') ?>
                    </a>
                </div>
            </div>
        </div>
    <?php 
    }
    }else{ ?>
    <h5 class="text-center mx-auto mt-3">
        <?php echo __('What you are looking for is not currently found. Please check the case','booksinfo'); ?>
    </h5>
    <?php }
       }
        }
        add_action('wp_ajax_nopriv_users_data_fetch','users_data_fetch');
        add_action('wp_ajax_users_data_fetch' , 'users_data_fetch');
    

    This is the best way I found to do it, here’s the example page that I gave
    page link

Comments are closed.