• UM provide member directory search feature, but it not working when we put User ID to the search field.
    How to custom search field ONLY for User ID?

    Note : I’m using UM version 2.5.0

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @aksin

    Here’s an article about the search options in the member directory:https://docs.ultimatemember.com/article/1513-member-directories-2-1-0#search

    I suggest you also check this article:Limit the Search in Member Directory with UM Custom Meta Data table

    Thread Starter aksin

    (@aksin)

    I have tried using following code, but still not working. The idea is only search for the user ID with meta table for meta key “um_user_profile_url_slug_user_id”.

    Is there any idea?

    add_action(“um_pre_users_query”,”um_061522_pre_users_query”, 10, 3 );
    function um_061522_pre_users_query( $obj, $directory_data, $sortby ){

    if( $obj->is_search == true && ! empty( $_POST[‘search’] ) ){

    if( ! empty( $obj->where_clauses ) ){
    foreach( $obj->where_clauses as $k => $w ){
    if( strpos( $w, ‘umm_search’ ) > -1 ){
    $w = explode(” OR “, $w );
    $obj->where_clauses[ $k ] = str_replace(“( umm_search.um_value = “, “( umm_search.um_key = ‘um_user_profile_url_slug_user_id’ AND umm_search.um_value LIKE “, $w[0] . ‘%’ ) . ‘)’;
    }
    }
    }
    }
    }

    Thank for advance

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @aksin

    Thank you for contacting our support.

    Are you using the UM custom meta table? The above example is for the UM custom meta table.

    Regards,

    Thread Starter aksin

    (@aksin)

    Hi,

    I just follow @gelieys suggestion ( Limit the Search in Member Directory with UM Custom Meta Data table )

    and in existing my data for user meta “um_user_profile_url_slug_user_id” like this (e.g user id 900):

    array (
      0 => '900',
    )

    What we need to achieve is to search user using User ID only.

    Thank

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @aksin

    Do you have a custom text field set in the Member Directory search form?

    Here’s an example code snippet to filter the member directory by a given User ID( if you need to search different User ID, you must add text field in the search form ):

    add_filter("um_prepare_user_query_args","um_custom_prepare_user_query_args", 99999 );
    function um_custom_prepare_user_query_args( $args ) {
    	$user_id = 123;
    
    	$args['meta_query'][ ] = array(
    			'relation' => 'OR',
    		   	array(
    				"key" => 'um_user_profile_url_slug_user_id',
    				"compare" => "=",
                                    "value" => $user_id,
      		   	)
    	);
    
    	
    	return $args;
    }

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Member Directory Search User ID’ is closed to new replies.