Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add a variable in bp_has_members

  • @jordi-radstake

    Participant

    I have this code in the members loop:

    <?php if (bp_has_members( array( 'include' => include_by_meta('Woman', 'Gender'), 'type' => 'newest') )) : ?>

    What I want to do is to replace ‘Woman’ by the xprofile value of the current logged in user.

    Must be easy, but I can’t figrured it out.

Viewing 11 replies - 1 through 11 (of 11 total)
  • @jordi-radstake

    Participant

    Never mind, fixed it.

    <?php global $bp;
    $the_user_id = $bp->loggedin_user->userdata->ID;
    $the_user_login = $bp->loggedin_user->userdata->user_login; 
    $geslacht = bp_get_profile_field_data('field=Geslacht&user_id='.bp_loggedin_user_id());
    ?>
    
    <?php if (bp_has_members( array( 'include' => include_by_meta($geslacht, 'Geslacht'), 'type' => 'newest') )) : ?>

    (geslacht is dutch for gender btw.)

    @henrywright-1

    Member

    I noticed in your code these lines aren’t being used:

    global $bp;
    $the_user_id = $bp->loggedin_user->userdata->ID;
    $the_user_login = $bp->loggedin_user->userdata->user_login; 

    Unless you’re using $the_user_login or $the_user_id it should be safe to remove them.

    @jordi-radstake

    Participant

    Ok, thnx for mentioning that 🙂

    @henrywright-1

    Member

    bp_loggedin_user_id() will hold the exact same value as $the_user_id anyway.

    @jordi-radstake

    Participant

    Now I would have the same for group-members, but that seems not to work?

    @henrywright-1

    Member

    For the groups loop, you need to use bp_group_has_members() instead of bp_has_members()

    @jordi-radstake

    Participant

    I did, but that’s not working.

    <?php $geslacht = bp_get_profile_field_data('field=Geslacht&user_id='.bp_loggedin_user_id()); ?>
    
    <?php  //if ( bp_group_has_members( 'exclude_admins_mods=0' ) ) : ?>
    
    <?php if (bp_group_has_members( array( 'include' => include_by_meta($geslacht, 'Geslacht'), 'type' => 'newest') )) : ?>
    
    	<?php do_action( 'bp_before_group_members_content' ); ?>
    
    	<div class="item-list-tabs" id="subnav" role="navigation">
    		<ul>

    @jordi-radstake

    Participant

    Oh wait, it has to do with the function:

    function include_by_meta($theMetaValue, $theMetaField) {
     
            $memberArray = array();
     
                    if (bp_has_members()) :
                    while (bp_members()) :
                            bp_the_member();
                            $theFieldValue = bp_get_member_profile_data( 'field='. $theMetaField );
                            if ($theFieldValue==$theMetaValue) {
                                    array_push($memberArray, bp_get_member_user_id());
                            }
                    endwhile;
                    endif;
     
            $theIncludeString=implode(",",$memberArray);
     
            return $theIncludeString;
    }
    

    @jordi-radstake

    Participant

    Why can’t I just copy that function?

    function include_by_meta_group($theMetaValue, $theMetaField) {
     
            $memberArray = array();
     
                    if (bp_group_has_members()) :
                    while (bp_group_members()) :
                            bp_group_the_member();
                            $theFieldValue = bp_get_member_profile_data( 'field='. $theMetaField );
                            if ($theFieldValue==$theMetaValue) {
                                    array_push($memberArray, bp_get_member_user_id());
                            }
                    endwhile;
                    endif;
     
            $theIncludeString=implode(",",$memberArray);
     
            return $theIncludeString;
    }

    @henrywright-1

    Member

    I’m not very familiar with the groups loop (never had groups enabled) but, yes, in theory there is nothing to stop copying functions you need from the BP core, modifying them for your purpose then adding them to your theme’s functions.php file for your own custom use.

    @jordi-radstake

    Participant

    Other question, is it possible to add multiple includes to this?

    <?php if (bp_group_has_members( array( 'include' => include_by_meta($geslacht, 'Geslacht'), 'type' => 'newest') )) : ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add a variable in bp_has_members’ is closed to new replies.
Skip to toolbar