Page 1 of 1

<?php echo get_user_field("city"); ?>

PostPosted: April 11th, 2011, 8:04 pm
by rvlatum
I am trying to add a few custom fields to the author page. I used this:

Code: Select all
<?php echo get_user_field("city"); ?>


Works great for the user that's logged in, but how can I show a field from on a profile from any user?
I tried

Code: Select all
<?php echo get_current_user_field("city,"); ?>


But that didn't work. What am I doing wrong?

Thanks a lot!

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 3:07 am
by Cristián Lávaque
You can specify the ID of any user you want the field from. ;)

From s2member/includes/functions/api-functions.inc.php
Code: Select all
/*
Retrieves a Custom Field value.
$field_id - required argument.
$user_id - defaults to current user.
*/
if (!function_exists ("get_user_field"))
    {
        function get_user_field ($field_id = FALSE, $user_id = FALSE)
            {
                return c_ws_plugin__s2member_utils_users::get_user_field ($field_id, $user_id);
            }
    } 


I hope that helps. :)

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 9:53 am
by rvlatum
Thanks, but that didn't work for me. What I need is a 'profile page' with info from the S2 plugin.
I am using the author page for this. After a user is logged in, I need that page to show some fields from the plugin. Now, it's showing the info from the user that is logged in, but I need it to show the info from the user's profile that I am visiting.

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 10:50 am
by Cristián Lávaque
OK, I think I understand what you want to do. That function should be what you need.

If you look at the function parameters, you'll notice the optional value for user ID, which defaults to the current user. So, if you want it to be for some other user, just pass his ID when calling the function. Like this:

Code: Select all
get_user_field('city'23); // 23 is the user's ID. 

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 10:57 am
by rvlatum
ok. but it's in the wordpress author.php file and I need it to show some fields from a user who's profile I am on.
wordpress does this like this:

Code: Select all
<?php global $current_user; get_currentuserinfo(); echo $curauth->display_name; ?>


I can't work with individual ID's, I need something like the example above.

Thanks for your help by the way!

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 8:43 pm
by Jason Caldwell
In your example, you would get the ID like this.
Code: Select all
<?php
$current_user 
= wp_get_current_user();
$user_id = $current_user->ID;
?>


Another technique, if you know their Username:
Code: Select all
<?php
$user 
= new WP_User("johndoe22");
$user_id = $user->ID;
?>


You can also use the get_users() function.
http://codex.wordpress.org/Function_Reference/get_users
Code: Select all
<?php
foreach(get_users("role=s2member_level1") as $user)
    $user_id = $user->ID;
?>

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 8:57 pm
by rvlatum
I still don't understand how to add the content of certain custom fields in my author page.
Example. I have three custom fields in the s2 plugin (bio, company profile and company)
How can I show the content of these fields for every user?

two random profiles (author.php)
see: http://www.entrepreneur21.net/author/sr ... rated-com/
http://www.entrepreneur21.net/author/rvlatum/

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 12th, 2011, 9:08 pm
by Jason Caldwell
Thanks for the follow-up.

Once you have the User's ID, you can use this s2Member API function.
Code: Select all
<?php get_user_field("city", $user_id); ?>
Where "city" is the Custom Field ID that you configured with s2Member.

Integrating this into the author.php file is another matter. If you need assistance with custom coding, you might post a project request here: viewforum.php?f=37

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 13th, 2011, 4:28 pm
by rvlatum
I noticed that the author.php file is using this to get the userdata:

Code: Select all
<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
get_userdatabylogin(get_the_author_login());
(
get_the_author_login());
else :
$curauth = get_userdata(intval($author));
endif;
?>


I tried everything, but I can't get it to work. I posted this in the custom coding section of your forum, but no luck so far. Any other suggestions?

Thanks for your help!

Re: <?php echo get_user_field("city"); ?>

PostPosted: April 13th, 2011, 4:51 pm
by Cristián Lávaque
You could try http://jobs.wordpress.net too. :)