Search code examples
phppermalinksbuddypress

Buddypress permalink profile data


I have buddypress installed on Kleo theme. I am using the DW Question and Answer plugin.

I want to display a profile field from buddypress next to the author of the questions in the DWQA plugin. I know that I need to edit the following files:

templates/content-single-question.php : line 17 -> 21
templates/content-single-answer.php: line 21 -> 29
templates/content-question : line 12 -> 27

I have added the following code at lines 17 -> 21 in the above file:

<div class="item-forum">
            <a href="<?php bp_member_permalink(); ?>"><?php bp_member_profile_data('field=Forum'); ?></a>                    
    </div>

But this does not work. When I view the code in Firebug it shows I have created the div but the link is empty ie <a href=""></a>

What am I missing?

When I diplay a buddypress profile field in the buddypress members directory using the same code it works.


Solution

  • The BP functions you are using only work on BP pages and in a BP loop.

    There are other functions for use on non-BP pages that do not use a BP loop.

    Try:

    <a href="<?php echo bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = true ); ?>"><?php echo xprofile_get_field_data( 'Forum', $user_id, $multi_format = 'comma' ); ?></a> 
    

    This example assumes that $user_id is set in the template above wherever you place this code.