0

I know you can easily display custom content if a certain logged in user is a certain role using

<?php if ( current_user_can('contributor') ) : ?>
    media files loop
<?php endif; ?>

However, I want to do the same thing, but for a specific username, not the logged in user.

I have user profiles in my wordpress website, some of them are artists, and If the profile being viewed is an artist I want to display their uploaded media. (and nothing to be returned if that profile being viewed is another role.)

I have the variable to get the currently viewed profiles username, I just need the if statement.

Something like:

media files loop
2

Chris Haugen,

You need to check user role who have 'artist' role and then you need to act on some video loop stuff.

Here's the solution:

$user = get_user_by('login', $username );

if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
        foreach ( $user->roles as $role ){             
           if($role == 'artist')
              media files loop
        }
}

get_user_by() is return user data of passed 'username'.

Thanks!

0

are you trying to check the "username"? if so:

<?php 
$user = wp_get_current_user();
$user = $user->user_login; ?>

<?php if($user == "John"): ?>
 media files loop
<?php endiif; ?>
  • Thanks for the reply, but no. I'm trying to see if a certain username is a specific role. It is NOT the user who is logged in. the username associated with a profile. I guess it would be something like: global $userpro; $other_username = get_query_var('up_username');``<?php if($other_username == "vendor"): ?> media files loop <?php endiif; ?> by vendor I mean the user role – Chris Haugen Jun 1 '15 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.