You can build a member directory for specific community role. Is that what you’re asking about?
Thanks!
No, because I don’t want to end up having a dozen different roles, since the main one is already highly customized, which means I’d have to edit too many roles if we make changes. Plus I want to have more control over the member directory, so want to build it from scratch.
So the goal is simply to have a shortcode like [member id=”4″] so that I can create my own categories for members on a custom directory page.
Does that make sense?
That feature does not exist in UM as of yet I am sorry.
Thanks!
Yes, I know it’s not an existing feature. Are you saying it’s not even possible to write a shortcode for it?
Yes exactly what I mean, we’ll work on something like that though.
Ah, ok. I’ll look at building something purely manual in the meantime.
peteratomic,
While you wait for the official UM shortcodes, you can build a custom display using the “Shortcode Exec PHP” plugin. It lets you create your own shortcodes using php.
Quick outline would be (using ‘role’ as that’s what I use):
extract(shortcode_atts(array(
'role' => 'Subscriber',
), $atts));
// The Query
$user_query = new WP_User_Query(array('role' => $role));
$html = '';
if (!empty($user_query->results)) {
$html .= '<table>';
// add table header row to html string
// Loop on users
foreach ($user_query->results as $user) {
$user_meta = get_user_meta($user->id);
$html .= '<tr>';
$html .= '<td>' . $user->id . '</td>';
$html .= '<td>' . $user->user_login . '</td>';
$html .= '<td>' . $user->display_name . '</td>';
// add user metadata to html string
$html .= '</tr>';
}
$html .= '</table>';
} else {
$html = 'No users found.';
}
return $html;
If you have complex fields (checkbox or dropdown) with multiple values, you need to unserialize them and loop on the values:
$html2 = '';
$serial_str = $user_meta['custom_field_name'][0];
if (is_serialized($serial_str)) {
$count = 0;
foreach (unserialize($serial_str) as $choice) {
if ($count > 0) { $html2 .= "<br />"; }
$html2 .= $choice;
$count++;
}
}
$html .= '<td>' . $html2 . '</td>';
Hope this helps.
Hi @yk11 – looks like that plugin was removed from the plugin repository for some reason. But maybe I can find something similar. Thanks for the tip!
This feature remains unavailable in UM core as of this moment, just as a note.
@peteratomic,
You can always add your own shortcode using the functions.php file.
Example (my own shortcode for logged in state):
function logged_in_func($atts, $content) {
extract(shortcode_atts(array('override' => false,), $atts));
$html = '';
if (is_user_logged_in() || $override == true) { $html = do_shortcode($content); }
return $html;
}
add_shortcode('logged_in', 'logged_in_func');
Yes this is possible to add your own custom built shortcodes.
Looks like a good shortcode for a personal sidebar… I’m using something like that, but in this case I need something a bit different… something that effectively works like:
[umprofile id=123]
So that I can grab the photo, name and title from a specific user, as I want to build a custom members directory.
(Was hoping someone in the UM community might have done this before.)
We’ll look at implementing such feature in the future.