Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

trying pulling back all users

Posted on 2011-09-14
18
Medium Priority
?
437 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:COwebmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 5

Accepted Solution

by:
KGNickl earned 288 total points
ID: 36535965
0
 
LVL 7

Assisted Solution

by:boon86
boon86 earned 288 total points
ID: 36536078
0
 

Author Comment

by:COwebmaster
ID: 36536121
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

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:COwebmaster
ID: 36536147
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?
0
 
LVL 23

Assisted Solution

by:jeremyjared74
jeremyjared74 earned 1140 total points
ID: 36536174
Use this piece of code to print all users for your blog:

<?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

0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36536177
The code can go anywhere in your themes template files.
0
 

Assisted Solution

by:COwebmaster
COwebmaster earned 0 total points
ID: 36536215
Okay, I place on a page (I have the plugin php execution installed) but nothing shows up on the page.  It's just blank.  I have 10 users in that table.
0
 
LVL 23

Assisted Solution

by:jeremyjared74
jeremyjared74 earned 1140 total points
ID: 36536230
It works for me. Try placing it at the very bottom of the header.php file just to make sure it is printing.

You need to add it to a template file for it to work.
0
 
LVL 23

Assisted Solution

by:jeremyjared74
jeremyjared74 earned 1140 total points
ID: 36536233
If you want to use it in your theme, you should make it a shortcode.
0
 
LVL 23

Assisted Solution

by:jeremyjared74
jeremyjared74 earned 1140 total points
ID: 36536235
"If you want to place it inside of a page or post"

It should be made into a shortcode.
0
 

Author Comment

by:COwebmaster
ID: 36536269
but I have php execution installed so I should be able to view that inside a page, right?
0
 

Author Comment

by:COwebmaster
ID: 36536342
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

0
 

Author Comment

by:COwebmaster
ID: 36536369
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?
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 284 total points
ID: 36536372
You might want to try something like this before you start trying to use the contents of $wp_user_search

var_dump($wp_user_search);
0
 

Author Comment

by:COwebmaster
ID: 36536428
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?
0
 

Author Comment

by:COwebmaster
ID: 36536460
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">
0
 

Author Comment

by:COwebmaster
ID: 36536668
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?
0
 

Author Closing Comment

by:COwebmaster
ID: 36558767
Thanks!
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to dynamically set the form action using jQuery.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question