PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

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

s2Member Plugin. A Membership plugin for WordPress®.

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

Postby rvlatum » April 11th, 2011, 8:04 pm

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!
Last edited by Cristián Lávaque on April 12th, 2011, 10:51 am, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
rvlatum
Registered User
Registered User
 
Posts: 6
Joined: April 11, 2011

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

Postby Cristián Lávaque » April 12th, 2011, 3:07 am

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. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

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

Postby rvlatum » April 12th, 2011, 9:53 am

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.
User avatar
rvlatum
Registered User
Registered User
 
Posts: 6
Joined: April 11, 2011

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

Postby Cristián Lávaque » April 12th, 2011, 10:50 am

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. 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

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

Postby rvlatum » April 12th, 2011, 10:57 am

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!
Last edited by Cristián Lávaque on April 12th, 2011, 11:14 am, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
rvlatum
Registered User
Registered User
 
Posts: 6
Joined: April 11, 2011

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

Postby Jason Caldwell » April 12th, 2011, 8:43 pm

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;
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

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

Postby rvlatum » April 12th, 2011, 8:57 pm

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/
User avatar
rvlatum
Registered User
Registered User
 
Posts: 6
Joined: April 11, 2011

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

Postby Jason Caldwell » April 12th, 2011, 9:08 pm

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
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

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

Postby rvlatum » April 13th, 2011, 4:28 pm

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!
Last edited by Cristián Lávaque on April 13th, 2011, 4:52 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
rvlatum
Registered User
Registered User
 
Posts: 6
Joined: April 11, 2011

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

Postby Cristián Lávaque » April 13th, 2011, 4:51 pm

You could try http://jobs.wordpress.net too. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron