Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display dropdown profile field data in Profile Header

  • @rgrober

    Participant

    Hello,

    What is the proper way to display dropdown profile field data in other places like the profile header?

    Here’s what I’ve written so far (works with text fields and checkbox fields):

    add_filter( 'bp_do_register_theme_directory', '__return_true' );
    function my_directory() {	
    if ( bp_is_active( 'xprofile' ) )
    
         if ( $memberRoles2 = xprofile_get_field_data( 'Starting', bp_get_member_user_id() ) ) :
    			echo '<h5 class="adneed">';
    		    echo '<span class="adneedcontent">';
    		    echo 'starting';
    		    echo '</span>';
    
    			foreach ( $memberRoles2 as $memberRoles2 ) { 
    						echo '<div class="roles">';
    						echo $memberRoles2; 
    						echo ',&nbsp</div>';
    					}
    			echo '</h5>';
    				endif;
    
    add_filter ( 'bp_directory_members_item', 'my_directory' );

    This is the error I get:

    Warning: Invalid argument supplied for foreach() in /home/tvfilmpa/staging/2/wordpress/wp-content/plugins/bp-custom.php on line 139

    Any help regarding this issue is greatly, greatly appreciated!

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

    Moderator

    You have several basic php mistakes in your function.
    I’m surprised that’s the only error you get.

    function my_directory() {	
       if ( bp_is_active( 'xprofile' ) ) {
    
         $memberRoles2 = xprofile_get_field_data( 'Starting', bp_get_member_user_id(), 'comma' );
    
         if ( $memberRoles2 != null && !empty($memberRoles2) ) :
    		echo '<h5 class="adneed">';
    		echo '<span class="adneedcontent">';
    		echo 'starting';
    		echo '</span>';
    		echo '<div class="roles">';
    		echo $memberRoles2; 
    		echo '</div>';
    		echo '</h5>';
    	endif;
      }
    }
    add_filter ( 'bp_directory_members_item', 'my_directory' );

    @rgrober

    Participant

    @shanebp, I really appreciate your help! I’m going to drop this in and see how it goes.

    I’m surprised I’ve made it this far, haha. I’m learning a lot.

    Thanks again!

    @shanebp

    Moderator

    btw – the hook is not a filter.
    So it may work, but should be:
    add_action( 'bp_directory_members_item', 'my_directory' );

    @rgrober

    Participant

    Thank you very much, @shanebp! I really appreciate you taking the time to help me out.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display dropdown profile field data in Profile Header’ is closed to new replies.
Skip to toolbar