Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sorting by xprofile field


  • lz430
    Participant

    @lz430

    Hi everyone. I’m kind of lost on how to sort by an xprofile field. My code is below which works fine on listing the appropriate members for each group. The groups being “Executive Board” and “Steering Committee”.

    I have tried adding the “type=”alphabetical”, however that doesn’t give any of the correct results. Instead it seems to list only a few of the members who are not even in the same group.

    My code is below:

    <?php
    /*
    Template Name: Buddypress Leadership Template
    */
    ?>
    
    <?php get_header(); ?>
    <?php if ( bp_has_members() ) : ?>
     
        <h4 id="executive-header">Executive Board</h4>
        <div class="leadership-list">
            <ul class="members-list executives leadership item-list" role="main">
           <?php while ( bp_members() ) : bp_the_member(); ?>
            <?php 
                global $current_site; 
                $user_id = bp_get_member_user_id(); 
                $memberOf = xprofile_get_field_data( 'Member of' ,bp_get_member_user_id(), $multi_format = 'array');
                $jobTitle = xprofile_get_field_data( 'Job Title' ,bp_get_member_user_id());
                $companyName = xprofile_get_field_data( 'Company' ,bp_get_member_user_id());
                $lastName = xprofile_get_field_data( 'Last Name' ,bp_get_member_user_id());
                if ($memberOf != '') {
                    foreach($memberOf as $key => $value){
                ?>
            <?php 
            if($value == "Executive Board") {?>
            
               <li class="member-dir-member">
                    <div class="column-first">
                        <div class="item-avatar">
                            <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
                         </div>
                     </div>
                    <!-- end column-first -->
                    <div class="column">
                        <div class="item">
                            <div class="item-title">
                                <a href="<?php bp_member_permalink(); ?>" class="member-name"><?php bp_member_name(); ?> <?php echo $lastName ?></a>  
                                <div class="job-title"> <?php echo $jobTitle; ?> of </div>
                                <div class="company-name"> <?php echo $companyName ?></div>
                            </div>  
                        </div>
                    </div>
                    <!-- end column -->
                    <div class="clear"></div>
                </li>
           
    
        <?php } ?>
        <?php     }
                } endwhile; ?>
     
         </ul>
        </div>
    
        <h4 id="steering-header">Steering Committee</h4>
        <div class="leadership-list">
            <ul class="members-list executives leadership item-list" role="main">
           <?php while ( bp_members() ) : bp_the_member(); ?>
            <?php 
                global $current_site; 
                $user_id = bp_get_member_user_id(); 
                $memberOf = xprofile_get_field_data( 'Member of' ,bp_get_member_user_id(), $multi_format = 'array');
                $jobTitle = xprofile_get_field_data( 'Job Title' ,bp_get_member_user_id());
                $companyName = xprofile_get_field_data( 'Company' ,bp_get_member_user_id());
                $lastName = xprofile_get_field_data( 'Last Name' ,bp_get_member_user_id());
                if ($memberOf != '') {
                    foreach($memberOf as $key => $value){
                ?>
            <?php 
            if($value == "Steering Committee") {?>
               <li class="member-dir-member">
                    <div class="column-first">
                        <div class="item-avatar">
                            <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
                         </div>
                     </div>
                    <!-- end column-first -->
                    <div class="column">
                        <div class="item">
                            <div class="item-title">
                                <a href="<?php bp_member_permalink(); ?>" class="member-name"><?php bp_member_name(); ?> <?php echo $lastName ?></a>  
                                <div class="job-title"> <?php echo $jobTitle; ?> of </div>
                                <div class="company-name"> <?php echo $companyName ?></div>
                            </div>  
                        </div>
                    </div>
                    <!-- end column -->
                    <div class="clear"></div>
                </li>
          
    
        <?php } ?>
        <?php     }
                } endwhile; ?>
     
          </ul>
        </div>
        <?php do_action( 'bp_after_directory_members_list' ); ?>
    
     <?php else: ?>
       <div id="message" class="info">
         <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
    
    <?php endif; ?>
    <?php get_footer(); ?>
    

    Any and all help is appreciated

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

  • lz430
    Participant

    @lz430

    Still needing help


    shanebp
    Moderator

    @shanebp

    >I have tried adding the “type=”alphabetical”

    It should be
    if ( bp_has_members( 'type=alphabetical' ) )

    When doing that, you should enable BuddyPress to WordPress profile syncing
    via Dashboard > Settings > BuddyPress > Settings


    lz430
    Participant

    @lz430

    I do have the BuddyPress to WordPress profile syncing enabled. I did add the code above as you suggested, however it doesn’t list the correct profiles.


    shanebp
    Moderator

    @shanebp

    Try using ‘alphabetical’ in the basic members loop.
    iow. without 2 while ( bp_members() ) : bp_the_member() loops and all the xprofile calls.

    That will determine if the problem is in BP or your code.


    lz430
    Participant

    @lz430

    Still kind of confused. Sorry for the delay between responses. I’ll be more responsive now.

    Where should I use the type=alphabetical now?
    Here’s my code again:

    <?php
    /*
    Template Name: Buddypress Leadership Template
    */
    ?>
    
    <?php get_header(); ?>
    <?php if ( bp_has_members() ) : ?>
     
        <h4 id="executive-header">Executive Board</h4>
        <div class="leadership-list">
            <ul class="members-list executives leadership item-list" role="main">
           <?php while ( bp_members() ) : bp_the_member(); ?>
            <?php 
                global $current_site; 
                $user_id = bp_get_member_user_id(); 
                $memberOf = xprofile_get_field_data( 'Member of' ,bp_get_member_user_id(), $multi_format = 'array');
                $jobTitle = xprofile_get_field_data( 'Job Title' ,bp_get_member_user_id());
                $companyName = xprofile_get_field_data( 'Company' ,bp_get_member_user_id());
                $lastName = xprofile_get_field_data( 'Last Name' ,bp_get_member_user_id());
                if ($memberOf != '') {
                    foreach($memberOf as $key => $value){
                ?>
            <?php 
            if($value == "Executive Board") {?>
            
               <li class="member-dir-member">
                    <div class="column-first">
                        <div class="item-avatar">
                            <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
                         </div>
                     </div>
                    <!-- end column-first -->
                    <div class="column">
                        <div class="item">
                            <div class="item-title">
                                <a href="<?php bp_member_permalink(); ?>" class="member-name"><?php bp_member_name(); ?> <?php echo $lastName ?></a>  
                                <div class="job-title"> <?php echo $jobTitle; ?> of </div>
                                <div class="company-name"> <?php echo $companyName ?></div>
                            </div>  
                        </div>
                    </div>
                    <!-- end column -->
                    <div class="clear"></div>
                </li>
           
    
        <?php } ?>
        <?php     }
                } endwhile; ?>
     
         </ul>
        </div>
    
        <h4 id="steering-header">Steering Committee</h4>
        <div class="leadership-list">
            <ul class="members-list executives leadership item-list" role="main">
           <?php while ( bp_members() ) : bp_the_member(); ?>
            <?php 
                global $current_site; 
                $user_id = bp_get_member_user_id(); 
                $memberOf = xprofile_get_field_data( 'Member of' ,bp_get_member_user_id(), $multi_format = 'array');
                $jobTitle = xprofile_get_field_data( 'Job Title' ,bp_get_member_user_id());
                $companyName = xprofile_get_field_data( 'Company' ,bp_get_member_user_id());
                $lastName = xprofile_get_field_data( 'Last Name' ,bp_get_member_user_id());
                if ($memberOf != '') {
                    foreach($memberOf as $key => $value){
                ?>
            <?php 
            if($value == "Steering Committee") {?>
               <li class="member-dir-member">
                    <div class="column-first">
                        <div class="item-avatar">
                            <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
                         </div>
                     </div>
                    <!-- end column-first -->
                    <div class="column">
                        <div class="item">
                            <div class="item-title">
                                <a href="<?php bp_member_permalink(); ?>" class="member-name"><?php bp_member_name(); ?> <?php echo $lastName ?></a>  
                                <div class="job-title"> <?php echo $jobTitle; ?> of </div>
                                <div class="company-name"> <?php echo $companyName ?></div>
                            </div>  
                        </div>
                    </div>
                    <!-- end column -->
                    <div class="clear"></div>
                </li>
          
    
        <?php } ?>
        <?php     }
                } endwhile; ?>
     
          </ul>
        </div>
        <?php do_action( 'bp_after_directory_members_list' ); ?>
    
     <?php else: ?>
       <div id="message" class="info">
         <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
    
    <?php endif; ?>
    <?php get_footer(); ?>
    

    lz430
    Participant

    @lz430

    I did find this:
    https://gist.github.com/mgmartel/4463855+&cd=8&hl=en&ct=clnk&gl=us

    But I’m not quite sure how to get it to work. I added it to my functions.php file and the page remains unchanged.

    Thoughts anyone??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sorting by xprofile field’ is closed to new replies.
Skip to toolbar