• Resolved Shea Media

    (@shea-media)


    Hi guys,

    I’ve been working on adding a small user directory to a membership plugin that I’m using. I’ve been able to isolate the “active” members, and print their names and user-profile descriptions. Where I’m running into problems is with applying the user_id from the user_meta database to the ID in the users database and then calling up the associated user_email and user_url.

    Here is the code that I have worked out so far:

    function directory($userlevel = '1', $show_fullname = true) {
    	global $wpdb;
    
    	$authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'mgm_status' AND meta_value = 'active'");
    
    	foreach ( (array) $authors as $author ) {
    		$author = get_userdata( $author->user_id );
    		$name = $author->nickname;
    		$des = $author->description;
    		if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) {
    			$name = "$author->first_name $author->last_name";
    		}
    		$link  = '<li style="display:none;"><b>' . $userlevelname[$userlevel] . '</b></li>';
    		$link .= '<div><strong>' . $name . '</strong><br /><p>' . $des . '</p></div>';
    		echo $link;
    	}
    }

    I’m not experienced working with databases or interacting with them so any advice would be a huge help to me.

    Thanks ahead of time.

Viewing 1 replies (of 1 total)
  • Thread Starter Shea Media

    (@shea-media)

    What I’d like to do is use something like this:

    $emailout = $wpdb->get_results("SELECT ID, user_email FROM $wpdb->users
    	WHERE id = $author);

    Right under:

    $des = $author->description;

    But this is mixing the tables in a way that brakes the site. I know from experience unfortunately. Anyone with experience working on this kind of function?

Viewing 1 replies (of 1 total)

The topic ‘Query both (users) and (usermeta) for directory function?’ is closed to new replies.