Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

trying pulling back all users

I'm trying to pull back all users from my db using a php script.  What do I need to adjust to make that happen?
<?php
    foreach(get_users() as $user)
        {
            $user = new WP_User($user);
            // print_r($user); for a list of properties available for display.
        }
    ?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of KGNickl
KGNickl
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Waller

ASKER

I'm using the wp membership plugin called s2member but the following does not pull back any users at all yet I have 10 users with the role s2member_level1

Any idea what I'm missing?
<?php
    foreach(get_users("role=s2member_level1") as $user)
        {
            $user = new WP_User($user);
            // print_r($user); for a list of properties available for display.
        }
    ?>

Open in new window

Also, in phpmyadmin, I see listed out in the usermeta table the following on each user:

a:1:{s:15:"s2member_level1";s:1:"1";}

Is that the role that I'm referring to in that query above?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code can go anywhere in your themes template files.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but I have php execution installed so I should be able to view that inside a page, right?
okay, I placed the code above in a separate php page outside of wordpress and nothing gets displayed in the output.  Permissions on all directories off of root are at 777 too.
<?php
    $wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
    foreach ( $wp_user_search as $userid ) {
    $user_id = (int) $userid->ID;
    $user_login = stripslashes($userid->user_login);
    $display_name = stripslashes($userid->display_name);
    $return = '';
    $return .= "\t" . '<li>'. $display_name .'</li>' . "\n";
    print($return);
    }
?>

Open in new window

Okay, I placed the code inside my functions.php page and names were displayed so that's good.  I realized that it had to fall under wordpress framework.  There is no header.php with this theme I'm using.

So if I can get it to pull back data through the functions.php page, then the issue is why can't I have that data display on a page?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I the code in above, then view the source code on the page, the source code stops at <div class="entry-content">

What would that indicate?
Okay, I tried var_dump($wp_user_search); and yes it display the results.  Also, I put up a header.php page and can list out the display names just fine.  It's just that when I try to add that php code in the html tab on a page, no names appear and in the source code, it stops at this line of code: <div class="entry-content">
Okay, I have it pulling back data now on the page using the following:

<?php
foreach (get_users () as $user)
{
$user = new WP_User ($user->ID);
echo get_user_field ("age", $user->ID);
print_r(get_s2member_custom_fields($user->ID));
print_r($user);
}
?>

However, it pulls back all the data on the user in an array.  How then would I parse out just the display name using the above code?
Thanks!