Question

I need word press only to give registered user profile results when doing a search.It has to restrict the search terms going into posts or other pages but only user profile and displays a link to view the full profile.I have tried many plugins but its not giving me the exact results.Is there any plugin or function to do that.Thanks!! Please Help

function wpb_users() { 

global $wpdb;

$randomusers = '<ul class="random-users">';

// Query database for users
$usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM         $wpdb->users ORDER BY RAND() LIMIT 5");

// Display users in a list
foreach ($usernames as $username) {

if (!$username->user_url) :

$randomusers .= '<li>' .get_avatar($username->user_email, 45) .$username->user_nicename."</li>";

else :

$randomusers .= '<li>' .get_avatar($username->user_email, 45).'<a     href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";

endif;
}
$randomusers .= '</ul>';

return $randomusers;  
}

add_shortcode('randomusers','wpb_users');

this gives me the list but no link and cannot restrict the search functionality

Was it helpful?

Solution

Use WP_User_Query, you can find here https://codex.wordpress.org/Class_Reference/WP_User_Query, works in same way as WP_Query, place code search.php and query there users by role and some other paramaters play around.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top