It all very much depends on where exactly you want to display the bio info.
$user_id
is the key variable you need, but obtaining this value is done differently depending on where you are on your website.
If you want to display bio info in a member’s blog post footer then add this to your theme’s single.php file:
<?php
$user_id = get_the_author_meta('ID');
echo xprofile_get_field_data('field=BIO', $user_id);
?>
Note: You will need to change BIO to whatever you’ve called your bio field when setting it up.
Thanks. I tried to put that code multiple places in my themes single.php and even the default buddypress theme trying all my field names with no results.
@3rdaxis did you change the field name to the name of your bio field?
you’re right, I just tested myself and it doesn’t do the job. This will work – I just tested it out on my dev install:
<?php
if ( $string = xprofile_get_field_data( 'BIO', get_the_author_meta('ID') ) ) {
echo $string;
}
?>
Note: Replace BIO with your field name.
Is the information for the bio going to come from one of my extended profiles i made when I replaced the field name in your code or is the info coming from the default wordpress bio section?
You have to give the field a title when you add new profile fields via WP Admin > Users > Profile Fields. Whatever you’ve chosen as your field title is what you should use
Thanks.. the second code you gave me works perfect.
I really appreciate your help. Thats the first bit of code that has worked to display the xprofile fields and iv tried allot.
Im not sure if you could help me with this one aspect. I would like to also call something like google+, twitter or facebook links that I created in the xprofile fields.
I can call those fields with the code posted here, but im wondering if @henrywright-1 or anybody stopping by this post could help with the code needed to make the called data as a link with alt text so it looks like Twitter, Google +, Facebook.
Thanks for any help or pointers
@3rdaxis
Untested but maybe something like this would work, in this example you would need to change “USERNAME” at the end of the URL to the persons twitter name. To get other URL’s to work you should just change the URL etc.
<?php
if ( $string = xprofile_get_field_data( 'BIO', get_the_author_meta('ID') ) ) { ?>
<a href="https://twitter.com/USERNAME" target="_blank" alt="twitter"><?php echo $string; ?></a> <?php
}
?>
As @henrywright-1 already stated “Replace BIO with your field name.”
Or:
<?php
if ( $string = xprofile_get_field_data( 'BIO', get_the_author_meta('ID') ) ) { ?>
<a href="https://twitter.com/USERNAME" target="_blank">Twitter: <?php echo $string; ?></a> <?php
}
?>
Thanks for your reply @bphelp I tried both codes and the second works to a point at where i need to be.
The thing im trying to do is call the xprofile field which would be where the author would place their twitter, google+ or facebook id and show it as a link.
The second code you gave me give the result Twitter:(and the user name i placed in the xprofile field) and as you would know takes me to twitter but not to the profile.
Is there a way that you know that would replace “username” with that actual username?
much thanks.
@3rdaxis
The problem is it would require that the username the user entered in the profile field to match their twitter id exactly. If not it may take them to god knows where. Anyway, this is untested but you can give it a whirl!
<?php
if ( $string = xprofile_get_field_data( 'BIO', get_the_author_meta('ID') ) ) { ?>
<a href="https://twitter.com/<?php echo get_the_author_meta('display_name'); ?>" target="_blank">Twitter: <?php echo $string; ?></a> <?php
}
?>
Much thanks to you @bphelp. That bit of code worked like clockwork. Yeah, i see the issue with having the wrong name in the field, but i will have instruction to double check and hopefully the authors will take note.
@3rdaxis
Glad I could help! Good luck with your BuddyPress site! 🙂
I think i spoke to soon about that working. In the front end the link looks good, but i had my own twitter account in place and so it looked like Twitter:(with my twitter name) when i would click that and thought it worked because i was already signed in.
Once i place a new twitter name in the profile, the front end looks right, “Twitter: chevrolet” just pulled one out of a hat, or any other twitter account, it goes right to my own profile or to twitter home page if not signed in.
So messing about i cam up with this ugly but working solution based on what was posted here.
it now bring the name in from the xprofile field into the url. Before it was grabbing a field from the wordpress profile.
<?php
if ( $string = xprofile_get_field_data( 'Twitter', get_the_author_meta('ID') ) ) { ?>
<a href="https://twitter.com/<?php if ($string =xprofile_get_field_data( 'Twitter', get_the_author_meta('ID') ) ) { echo $string;} ?>" target="_blank">Twitter: <?php echo $string; ?></a> <?php
}
?>