Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to hide visibility options for empty values

  • @asitha

    Participant

    Hi there,

    In Setting > Profile, I want to hide rows of fields that do not have a value set for them.

    Currently the code is as such:
    [ edited – please use the ‘code’ button when sharing code. ]

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    	<tr <?php bp_field_css_class(); ?>>
    		<td class="field-name"><?php bp_the_profile_field_name(); ?></td>
    		<td class="field-visibility"><?php bp_profile_settings_visibility_select(); ?></td>
    	</tr>
    <?php endwhile; ?>
    

    I have tried to add <?php if ( bp_field_has_data() ) : ?> but that doesn’t seem to hide the row either. I tried doing a var_dump of the bp_the_profile_field_value() but it returns NULL for all fields even though some of them do have values.

    Any suggestions on what I might be doing wrong here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • @shanebp

    Moderator

    Nice hat.

    Yes, the use ofbp_field_has_data() can be a bit confusing.
    Remember that in this context, rather than check the field value, it checks if there is data in the visibility setting for that field – which will always be true.
    And bp_the_profile_field_value will be NULL for the same reason.

    Try this:

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    	<?php 
    	$this_field = xprofile_get_field_data( bp_get_the_profile_field_id(), bp_displayed_user_id(), 'comma' ); 
    	if( !empty( $this_field ) ) :
    	?>
    	   <tr <?php bp_field_css_class(); ?>>
    		<td class="field-name"><?php bp_the_profile_field_name(); ?></td>
    		<td class="field-visibility"><?php bp_profile_settings_visibility_select(); ?></td>
    	   </tr>
    	<?php endif; ?>
    <?php endwhile; ?>

    @asitha

    Participant

    Thanks, Shane! That worked perfectly.

    Would it also be possible to add that if the visibility option is not editable, to hide it as well?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hide visibility options for empty values’ is closed to new replies.
Skip to toolbar