Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geotsiokos/a8a4e7e305977344fc12211512c94908 to your computer and use it in GitHub Desktop.
Save geotsiokos/a8a4e7e305977344fc12211512c94908 to your computer and use it in GitHub Desktop.
function my_affiliates_permanent_my_users( $atts ){
$output = "";
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$args = array(
'meta_key' => Affiliates_Permanent::REFERRER,
'meta_value' => $user->ID
);
$users = get_users( $args );
if ( isset( $users ) && ( sizeof( $users ) > 0 ) ) {
$output .= '<ul>';
foreach ( $users as $us ) {
$output .= '<li>' . $us->user_login . '</li>';
}
$output .= '</ul>';
}
}
return $output;
}
add_shortcode( 'affiliates_permanent_my_users', 'my_affiliates_permanent_my_users' );
@CMzKonsult
Copy link

CMzKonsult commented Sep 19, 2019

Thanks for this one!

One question, Is it possible to show usermeta like phone etc

@geotsiokos
Copy link
Author

You're welcome, I'm glad you found this shortcode useful.

That would depend on where this data is stored. If it's in the usermeta table, you can use the function get_user_meta() as described in the Codex:
https://codex.wordpress.org/Function_Reference/get_user_meta.
After fetching the meta you can print all that additional info for the user by appending it to $output.
Hope it helps.

Cheers

@CMzKonsult
Copy link

Thanks for your reply.

I did take a quick look on function get_user_meta() yesterday and I forgot to write back to you that I've found a solution.
Btw I did some rewriting and added 'role' => 'my role' to use this with different roles. So big thanks for your code.

@geotsiokos
Copy link
Author

That's great, I'm glad you resolved this and added further features.
Good to know that my code is useful.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment