0

I'm at a loss. I have profiles developed for my wordpress website, and I want to display content on my page-profile.php that is specific per user profile.

I've looked all around the codex and only found stuff like this: https://codex.wordpress.org/Function_Reference/get_user_meta that only gets the current logged in user

and this:https://codex.wordpress.org/Function_Reference/get_the_author that gets the current post author

Well, on a profile page there is no posts, so that returns null, and current user is wrong for obvious reasons. (it's only right if someone is viewing their own profile)

So does anyone know how to go about identifying the currently viewed profile's username or ID?

This: https://codex.wordpress.org/Function_Reference/get_author_posts_url can return a specific user's ID, however it is static, and I need mine to be dynamic based on which profile is viewed.

2
  • When do you show page-profile.php? How do you tell that this page should be shown and how do you know which author to show on this page? Do you use native /author/user/ page for this? May 30, 2015 at 8:37
  • Nope, I use a plugin called userpro. The profile page shows whenever a user clicks on another users profile card. I would assume it uses the native author functionality though May 30, 2015 at 8:50

1 Answer 1

1

On an author archive page (assuming the plugin uses the core archives) get_queried_object() will return the WP_User object for the author. Something like:

$author = get_queried_object();
if (is_a($author, 'WP_User')) {
  var_dump($author->data);
}

You should see the login, nicename, and display name in there. Use what you need.

1
  • Thanks a lot :) I used $author = get_queried_object(); var_dump($author); and found out this is actually a WP_post page. I think I can handle the rest ;) Thanks for the invaluable tool, never knew about get_queried_object May 30, 2015 at 22:42

Your Answer

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

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