Title: Hide empty field groups
Last modified: August 31, 2016

---

# Hide empty field groups

 *  Resolved [carson7634](https://wordpress.org/support/users/carson7634/)
 * (@carson7634)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/hide-empty-field-groups/)
 * Hello Jacob,
 * Your plug-in is great. This really should be a standard feature in BuddyPress.
 * My question is:
 * Is there a way to modify the code of your plug-in, so that if all fields within
   a group are empty, then that group’s tab is not displayed?
 * Any assistance is greatly appreciated.
 * Thank you.
 * [https://wordpress.org/plugins/buddypress-profile-tabs/](https://wordpress.org/plugins/buddypress-profile-tabs/)

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

 *  Thread Starter [carson7634](https://wordpress.org/support/users/carson7634/)
 * (@carson7634)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209937)
 * After staring at the code for a few hours, I came up with this. Works like a 
   charm for me. Even uses the ‘error_log()’ function to tell you what fields are
   found to be “not empty.” I found that the URL field type always comes back not
   empty. I’m sure this could be corrected with a tweak, but I don’t need it to 
   work this way.
 * Paste this code into the “class-bp-profile-tabs.php” file located in “wp-content/
   plugins/buddypress-profile-tabs/public”
 * Paste it just below
    `$member_type = bp_get_member_type( $current_user_id );`
 * but above
    `if ( ! empty( $member_type ) )`
 *     ```
       // Loop removing empty groups
       foreach ( $this->groups_list as $tab_group_index => $tab_group )
       {
               /* SQL Query for profile fields */
       	$profile_fields_query = 'SELECT id, group_id, name FROM '.$wpdb->prefix.'bp_xprofile_fields WHERE group_id='.$tab_group->id;
   
       	/* Gets profile fields from database */
       	$this->fields_list = $wpdb->get_results( $profile_fields_query );
   
       	/* flag for non empty fields within group */
       	$tab_group_is_empty = true;
   
       	/* Check if each field is empty, if one is found to not be empty, set flag to false and break */
       	foreach( $this->fields_list as $field_index => $profile_field )
       	{
       		// Args for getting profile field data
       		$field_args = array('field' => $profile_field->id, 'user_id' => bp_displayed_user_id());
   
       		// Get profile field data
       		$field_value = bp_get_profile_field_data($field_args);
   
       		// Check if empty
       		if(!empty($field_value))
       		{
       			error_log('Value Found: '.$tab_group->name.' - '.$profile_field->name);
   
       			// If not empty, set flag to false and break out of loop.
       			$tab_group_is_empty = false;
       			break;
       		}
       	}
   
       	// Remove tab group if it is empty
       	if($tab_group_is_empty)
       	{
       		unset( $this->groups_list[ $tab_group_index ] );
       		$this->tabs_to_filter .= $tab_group->id . ',';
       	}
   
       }
       ```
   
 *  Plugin Author [Jacob Schweitzer](https://wordpress.org/support/users/primetimejas/)
 * (@primetimejas)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209947)
 * Hi carson7634,
    Thank you for the contribution, however I’m sorry I wasn’t able
   to get this in the latest version. I will look at it for a future version, reason
   being I don’t want to add another database call in there if it is not necessary
   so probably the best way would be to add an option that says “Do not show empty
   tabs” which is not enabled by default to keep the plugin fast. If the option 
   is enabled then it would use code similar to something you provided here to look
   for empty tabs then not include them. What do you think?
 *  [thavaz](https://wordpress.org/support/users/thavaz/)
 * (@thavaz)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209952)
 * Hi there guys, sorry to jump in here. Been looking for a solution to this riddle.
   [@carson7634](https://wordpress.org/support/users/carson7634/) thanks for taking
   the time to write out that code mate, really appreciate it.
 * I tried inserting it between:
    $member_type = bp_get_member_type( $current_user_id);
   and if ( ! empty( $member_type ) ) {
 * however it does not seem to hide the empty Tabs. Any assistance here would be
   much appreciated
 *  Thread Starter [carson7634](https://wordpress.org/support/users/carson7634/)
 * (@carson7634)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209956)
 * Hello Jacob,
 * I totally understand not wanting another database call. I am new to wordpress
   and php (more of a c++/Java guy) so these are the things I should learn about.
   Fortunately this did work for me, but I agree that it might not be the best solution.
   I feel like the implementation that you described would be excellent.
 * Thavaz,
 * I am sorry, I think I posted that without fully testing it. I actually see the
   loop in a different location in my installation. It needed to be placed earlier.
   Use with caution, and if Jacob implements this feature, burn my code with fire!
   😛
 * In my installation it is between:
    ‘$this->groups_list = $wpdb->get_results( 
   $profile_field_groups_query );’ and ‘$current_user_id = get_current_user_id();’
 *  [thavaz](https://wordpress.org/support/users/thavaz/)
 * (@thavaz)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209957)
 * [@carson7634](https://wordpress.org/support/users/carson7634/)
    Mate, you are
   too awesome! Thank you for the patch, it worked fantastically 🙂 After placing
   the code in and uploading I initially had an error, however this was due to a
   caching plugin, after clearing it, all worked like a charm.
 * Thanks again gentleman, especially @ you carson7634! Thumbs up.
 *  Thread Starter [carson7634](https://wordpress.org/support/users/carson7634/)
 * (@carson7634)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209958)
 * You are welcome, but credit goes to Jake for creating the plug-in to begin with.
   Buddy press really should pay the man and add this as a stock feature!
 *  [thavaz](https://wordpress.org/support/users/thavaz/)
 * (@thavaz)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209960)
 * [@carson7634](https://wordpress.org/support/users/carson7634/) very true. +100
   to your comment above mate. What a powerful plugin, it completely adds versatility
   to that lacking dimension of BP’s customization of independent profiles.
    Fantastic
   work [@jacob](https://wordpress.org/support/users/jacob/) Schweitzer! and most
   of all, thank you for making it freely available 🙂
 *  [nnyorker](https://wordpress.org/support/users/nnyorker/)
 * (@nnyorker)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209965)
 * Thank you all for your contributions. I am having trouble finding either of these
   locations to insert the code. Can you help?
    Thanks! Anna
 *  [thavaz](https://wordpress.org/support/users/thavaz/)
 * (@thavaz)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209967)
 * hey there Anna, how far did you get?
    Did you perhaps locate the files that you
   need to insert the above into? Or are you having tough time finding the segment
   of code to dissect and inject carson7634’s bit of code?
 *  [nnyorker](https://wordpress.org/support/users/nnyorker/)
 * (@nnyorker)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209968)
 * Hi there Thavaz.
    Thank you for your reply. I am not able to find this location
   in the file: In my installation it is between: ‘$this->groups_list = $wpdb->get_results(
   $profile_field_groups_query );’ and ‘$current_user_id = get_current_user_id();’
 *  Thread Starter [carson7634](https://wordpress.org/support/users/carson7634/)
 * (@carson7634)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209969)
 * What editor are you using to modify the file?
 *  [nnyorker](https://wordpress.org/support/users/nnyorker/)
 * (@nnyorker)
 * [10 years ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209971)
 * Hi there – I am using text edit in the mac.
    Actually I did find it near the 
   end of the file, but uploaded it and everything went white, so I had to revert
   back to original. Anyone else have that happen?
 *  [nnyorker](https://wordpress.org/support/users/nnyorker/)
 * (@nnyorker)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209983)
 * Hi there – anyone else have any luck hiding empty field groups?
    Thanks Anna

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

The topic ‘Hide empty field groups’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-profile-tabs.svg)
 * [BuddyPress Profile Tabs](https://wordpress.org/plugins/buddypress-profile-tabs/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/buddypress-profile-tabs/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-profile-tabs/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-profile-tabs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-profile-tabs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-profile-tabs/reviews/)

 * 13 replies
 * 4 participants
 * Last reply from: [nnyorker](https://wordpress.org/support/users/nnyorker/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/hide-empty-field-groups/#post-7209983)
 * Status: resolved