Tagged: code
Hi Swati,
by user id, you mean the numeric user id or the alphabetic username?Thank you
BrajeshHi Swati,
Thank you for clarifying.Please put the following code in your bp-custom.php
/** * Search a member list by the user id */ function buddydev_search_member_by_user_id( $args ) { if ( empty( $args['search_terms'] ) ) { return $args; } $term = $args['search_terms']; if ( is_numeric( $term ) ) { $args['include'] = absint( $term ); // only this user please $args['search_terms'] = ''; // reset search term } return $args; } add_filter( 'bp_after_has_members_parse_args', 'buddydev_search_member_by_user_id' );
Now if you use numeric id in the directory search form, it will list that user.
Hope that helps.
Hi Brajesh ji,
Thanks a lot, it’s working…
I want some more implement in it as in member directory (member-loop.php), I inserted the following code as given below for showing user ID.
<?php echo “INDIA77”?><?php echo bp_get_member_user_id(); ?>
// used “INDIA77” as prefix with user id. If the user id is 25, then the result for user id would be INDIA7725.
But user don’t know that “INDIA77” is prefix, and he would be interested to insert full user id with prefix in search form. so how we can implement this ??
Thank you
Hi Swati,
Thank you.You can use the following code to do that
/** * Search a member list by the user id with prefixed username */ function buddydev_search_member_by_user_id( $args ) { if ( empty( $args['search_terms'] ) ) { return $args; } $prefix = strtolower( "INDIA77" ); // Change the prefix if you are using a different prefix $term = strtolower( trim( $args['search_terms'] ) ); if ( stripos( $term, $prefix ) === 0 ) { //must start with $id = str_replace( $prefix, '', $term ); $args['include'] = absint( $id ); // only this user please $args['search_terms'] = ''; // reset search term } return $args; } add_filter( 'bp_after_has_members_parse_args', 'buddydev_search_member_by_user_id' );
here we are making sure that our search term starts with the “prefix” and then we replace the prefix to find the id. rest is same.
Hope that helps.
Regards
Brajesh
The topic ‘ [Resolved] search user by "USER ID"’ is closed to new replies.