0

My site has a user profile page. For some reason I would like to pull user profile data in my plugin.

I know I can pull logged in user profile data using get_currentuserinfo();.

For example I would like to get displayed profile user id.

Can anyone tell me how to pull it.?

3 Answers 3

1

If you're trying to get user data for the displayed profile, you can do it like so:

$thisauthor = get_userdata(intval($author));

That'll return an object filled with everything you need. For instance, if you need the user ID, you can call it like so:

$thisauthor->ID

I use this extensively on the profiles on my site: http://androidandme.com/user/clark

UPDATE

In a plugin, it looks like you need to call the global variable first, like so:

global $author; $thisauthor = get_userdata(intval($author));

4
  • But the problem is I need the profile id value within a plugin. I've tried your code already. Its not working within a plugin. Nov 3, 2012 at 17:46
  • Finally I end up using sessions to store the current profile ID. By the way can you help me with this question ? Nov 3, 2012 at 17:49
  • Does adding a global $author help anything?
    – clark
    Nov 3, 2012 at 17:57
  • You are diamond mate. It works when I add global variable!!! Thanks Nov 3, 2012 at 18:11
1

Take a look at:

get_user_by() at http://codex.wordpress.org/Function_Reference/get_user_by

1

You can access your wp_users table using WP_User_Query. http://codex.wordpress.org/Class_Reference/WP_User_Query

For example:

$author_query = new WP_User_Query();

// Get the results
$authors = $author_query->get_results();

A more comprehensive example can be seen here: http://wpsmith.net/2012/wp/an-introduction-to-wp_user_query-class/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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