Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to not show buddy x-profile fields on bbpress if not filled in?


  • Robkk
    Moderator

    @robkk

    im trying to put buddypress x-profile fields in bbpress on loop-single-reply.php after the author role and avatar

    I have created one called Location

    my function to display it is

    <div class="bbp-usr-location"><?php
    if ( bbp_is_topic_anonymous() ) {
    		echo "<br>Guest Post"; }
    		elseif ( bbp_is_reply_anonymous() ) {
    		echo "<br>Guest Post"; }
    		else {
      $user_location = xprofile_get_field_data( 'Location', ( bbp_get_reply_author_id ( bbp_get_reply_id() ) ) );
       echo 'Location: ' . $user_location; }
    ?></div>

    I just want to not display it if its not filled in on buddypress

    Any Help?

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

  • Robin W
    Moderator

    @robin-w

    Not sure if this parameter is there ie set or just blank in buddypress

    However you can test if empty – empty meaning not set or set to 0 or set to “”

    by changing

    echo 'Location: ' . $user_location; 
    

    to

    if (!empty($user_location)) {echo 'Location: ' . $user_location; }
    

    Robkk
    Moderator

    @robkk

    Nevermind i got it to work , plus that code i just posted is all out of wack , just some copy and pasting from other functions that worked


    Robkk
    Moderator

    @robkk

    This is what i used

    <div class="bbp-usr-location"><?php
    $bpProfileField = bp_get_profile_field_data( 'field=Location &user_id=' . get_the_author_meta( 'ID' ) );
    if ( empty ( $bpProfileField) ):
    ?>
    <p></p>
    <?php else: ?>
    <p><?php echo 'Location: ' . $bpProfileField; ?></p>
    <?php endif; ?></div>

    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed !

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