• The users of our new intranet that we have developed using wordpress and ultimate member have asked if we are able to provide additional functionality for them.

    Currently, we have an “our people” page where users can search for people throughout our company using their first name and surname, which works using code that was provided ultimate member to allow this.

    HR would now like us to be able to search by a users number plate which will then tell HR who that car belongs to – for example, in a case that something has happened to the car or it is blocking an entrance etc.

    Here is the code that we are trying / the code that ultimate member gave us:

    add_filter( 'um_member_directory_general_search_meta_query', 'cust_search_usrs', 10, 2 );
    function cust_search_usrs( $meta_query, $search ){
        $meta_query = array();
        return $meta_query;
     }
    add_filter( 'um_prepare_user_query_args', 'um_user_before_query_usrs', 10, 2 );
    function um_user_before_query_usrs( $query_args, $directory_data ){
    global $current_user;
    global $current_user_Location;
    get_currentuserinfo(); 
    
    $current_user = wp_get_current_user();
    
    if( isset( $_POST['search'] ) && $_POST['search'] != '' ) {
               $query_args['search_columns'] = array( 'first_name', 'last_name', 'display_name', 
    'Job_Title', 'Department_Team', 'Extension', 'Mobex', 'mobile_number', 'numberplate1' );
               $query_args['search']         = '*' . $_POST['search'] . '*';
        }
        return $query_args;
       }
    

    The numberplate1 is metadata which is part of our table that we have for each user.

    What we would like to achieve is that the search feature will allow the user to search a numberplate and it will return a result based on that numberplate.

    Could anyone please help us with this?

    Thanks!

    • This topic was modified 4 years, 11 months ago by aralmac123.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @aralmac123

    What’s the version of UM installed on your site? Have you tried adding a custom directory filter that matches the meta keys?

    Please read this doc: https://docs.ultimatemember.com/article/1513-member-directories-2-1-0

    Regards,

    Thread Starter aralmac123

    (@aralmac123)

    Hi @champsupertramp ,
    thanks for your reply!

    Our version is 2.1.2.
    I believe that we can filter by a custom field but what we are trying to achieve is that the user can actually search by that custom field.
    In our case it is by number plate. So, I can enter my number plate, click search and it will return my user profile that is associated with that number plate.

    Can this be achieved?

    Also, the code we have shown you above was give to us by UM, however, search results only return when searched by first name and surname. Should it not work when we search for other meta such as department etc based on the code they give us?

    Thanks in advance for any help ??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @aralmac123

    UM is using the standard WP User Query class to retrieve profiles. Using the filter hooks in the code provided above, you can add extra meta queries. Please see this doc for more details:
    https://codex.www.ads-software.com/Class_Reference/WP_User_Query#Custom_Field_Parameters

    Regards,

    Thread Starter aralmac123

    (@aralmac123)

    Hi @champsupertramp ,
    How would we get what the user has entered into the search bar in order to use it in the wp_query?

    Hi, i have a similar problem. I also do have a custom field (the same), for a group of people where some of them are members (subscribers), and some are leaders.
    People of this group all do have the same custom field (advisoryID)

    I would need a hook into members page, which if accessed by the leader with advisoryID = 22 (example),
    only members with the same value in advisoryID will be shown.

    Could you please lead me in the right direction? Thanks a lot.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WordPress/Ultimate Member- Search feature by metadata’ is closed to new replies.