Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Display xProfile field groups

Viewing 6 replies - 1 through 6 (of 6 total)

  • danbp
    Moderator

    @danbp

    hi @pstidsen,

    not sure i understand what you want. But if your goal is to fetch a xprofile data and show it somewhere on your site (aka outside of the profile loop), you can use a function like these:

    function pstidsen() {
             // we need the user_id first (mandatory outside a loop)
    	$user_id = bp_get_activity_user_id();
            // now we fetch the field data (separate fied id's by comma)
    	$my_field = xprofile_get_field_data('4, 41,55', $user_id);
    	// we built the output
    	echo '<div class="authorinfo">'. $my_field . '</div>';
    	
    }
    // the new hook
    add_action( 'show_pstidsen', 'pstidsen' );
    // finally add this placeholder in the appropriate template
    <?php do_action( 'show_pstidsen'); ?> 

    pstidsen
    Participant

    @pstidsen

    Hi danbp and thanks.

    I have inserted this:

    function pstidsen() {
             // we need the user_id first (mandatory outside a loop)
    	$user_id = bp_get_activity_user_id();
            // now we fetch the field data (separate fied id's by comma)
    	$my_field = xprofile_get_field_data('4, 41,55', $user_id);
    	// we built the output
    	echo '<div class="authorinfo">'. $my_field . '</div>';
    	
    }
    // the new hook
    add_action( 'show_pstidsen', 'pstidsen' );

    I my functions.php and the last line in my template, but it doesn’t work. I get this error:

    Fatal error: Call to undefined function bp_get_activity_user_id() in /data/home/nagcolle/public_html/designerspace.dk/ds/wp-content/themes/bp-mag-child/functions.php on line 17


    shanebp
    Moderator

    @shanebp

    It seems you are on a member profile page, so try using bp_displayed_user_id() instead.


    pstidsen
    Participant

    @pstidsen

    Now the function is runned, but no fields are shown. My code is:

    //Prints xProfile
    function PrintKontaktinformationer() {
    	// we need the user_id first (mandatory outside a loop)
    	$user_id = bp_displayed_user_id();
    	// now we fetch the field data (separate field id's by comma)
    	$my_field = xprofile_get_field_data('10, 9, 1, 11, 12, 13, 14, 15', $user_id);
    	// we built the output
    	echo '<div class="authorinfo">TEST'. $my_field . '</div>';
    }
    // the new hook
    add_action( 'show_PrintKontaktinformationer', 'PrintKontaktinformationer' );

    shanebp
    Moderator

    @shanebp

    Try fetching just one field. If you pass in an id, don’t make it a string.

    $my_field = xprofile_get_field_data(10);
    or
    $my_field = xprofile_get_field_data(10, $user_id);

    Because you’re in a sidebar, this may not work, but replace ‘Company’ with a field name and try:

    $my_field = bp_get_member_profile_data( 'field=Company' );


    pstidsen
    Participant

    @pstidsen

    It works just with one field! Perfect!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Display xProfile field groups’ is closed to new replies.
Skip to toolbar