I want to replace get_author_link() and get_the_author_meta($feld)
with something equivalent to point to the author of the current post Buddypress user profile page and retrieve a specific profile field from his Buddypress page
ie, I just want to show a link to the post user profile and a biography from one of his BP profile fields
I’m not sure which functions I should use for this… BuddyPress documentation is still not very clear unlike the WP Codex…
thanks
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
For an author’s profile link, use
bp_core_get_user_domain( $user_id )
to get the URL, and
bp_core_get_userlink( $user_id )
to get an HTML link element, including display name.
For the xprofile data, use
xprofile_get_field_data( $field, $user_id )
$field can be either the name of the field (like ‘Biography’) or the numerical field id.
Method 2
It’s kind of a bit different, but since this thread appears first on Google, it might be usefull for someone else.
To get the current logged-in user profile link, just use bp_loggedin_user_domain()
Hope that helps.
Method 3
If you need to add it in comments:
<?php
$author_id = get_comment(get_comment_ID())->user_id;
if (function_exists('bp_get_profile_field_data')) {
$bp_name = bp_core_get_userlink( $author_id );
$bp_location = bp_get_profile_field_data('field=Location&user_id='.$author_id);
if ($bp_name) {
echo '<div>'. $bp_name . '</div>';
}
if ($bp_location) {
echo '<div class="authorinfo">'. $bp_location . '</div>';
}
}
?>
I included a sample profile field ‘location’, which may be removed. This is for displaying a link to comment author’s Buddypress profile. It must be placed inside your comments loop, which will look something like:
foreach($comments as $comment)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0