Skip to:
Content
Pages
Categories
Search
Top
Bottom

Trying to display a profile field on the site


  • r083r7
    Participant

    @r083r7

    I would like to display profile fields on different parts of the site.

    I read that BP comes with this function:
    https://codex.buddypress.org/developer/function-examples/bp_profile_field_data/

    I created a shortcode in my functions.php file:

    /* Dislay BP field */
    add_shortcode('bp_field_display', 'bp_profile_field_data');

    Then went and added this shortcode to one of my pages:
    [bp_field_display field="Register As"]

    I expected that it would show me the value of the field I have on my profile called Register As. I didn’t specify a user ID so it should return mine since I’m logged in.

    Instead, I got blank, nothing displayed at all.

    Any idea what I’m missing? I’m open to other suggestions but thought that making this shortcode wouild be the most direct and straight forward way.

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

  • shanebp
    Moderator

    @shanebp

    bp_profile_field_data() is a function, not a callback.

    You could do this:

    add_shortcode('bp_field_display', 'show_bp_profile_field_data');
    function show_bp_profile_field_data( $atts ) {
    
        $args = array(
           'field'     => $atts['show_field'],
           'user_id'   => get_current_user_id()
        );
    
        return bp_profile_field_data( $args );
    
    }
    
    // usage
    [bp_field_display show_field="Register As"]

    r083r7
    Participant

    @r083r7

    Thank you and I will test this out. I added it as a shortcode to one of my pages but noticed some issues, especially when I added several of these on the same page. Will troubleshoot to narrow down the problem and report back later this week.

    Thanks for your help so far 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar