Skip to:
Content
Pages
Categories
Search
Top
Bottom

Users based on location


  • stunomatic
    Participant

    @stunomatic

    I have 5 posts 1 on Canada, 1 on America, 1 on UAE, 1 on Russian etc.

    How I can echo those users who live in Canada inside any Canada post ? or Users living in America inside America Post ?

    Users while registering fill Address.

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

  • stunomatic
    Participant

    @stunomatic

    NO one ?


    shanebp
    Moderator

    @shanebp

    You’ll need to write some custom code.

    Add a buddypress members loop on the template you use to show your posts.

    Filter the members loop by their address.

    If you write some code and run into issues, you may get some feedback on these forums.

    Or you could post to the Jobs Board and hire a developer.


    stunomatic
    Participant

    @stunomatic

    Thanks @shanebp for response. OK I played around and here is my code. Its working fine but with one issue i.e

    If there is no value it echo’s all the members.

    
    <?php 		
    $contrytoggle = get_field( "country_toggle" );
    $contrypri = get_field( "select_country" ); ?>
    
         <?php echo $contrytoggle; ?>
    
    	<?php if ( bp_has_members( my_custom_ids( $contrytoggle, $contrypri ) ) ) : ?>
    	
    	<ul>
      <?php while ( bp_members() ) : bp_the_member(); ?>
     
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
     
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
          </div>
    	</li>
    	  
    	   <?php endwhile; ?>
    
    	</ul>
    	
    <?php else: ?>
     
       <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
       
       
    	
    <?php endif; ?>

    stunomatic
    Participant

    @stunomatic

    I use the function “my_custom_ids” Loop


    shanebp
    Moderator

    @shanebp

    Put the call to my_custom_ids before the members loop.
    Use a conditional to check if my_custom_ids is empty.
    If it’s empty, don’t call the members loop.


    stunomatic
    Participant

    @stunomatic

    Hi Shane,

    Even if I check condition it still shows all members.

     <?php       
    
        <?php if ( !empty(bp_has_members( my_custom_ids( 'country', 'usa' ) ) ) ) : ?>  
    
        <ul>
      <?php while ( bp_members() ) : bp_the_member(); ?>
    
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
    
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
          </div>
        </li>
    
           <?php endwhile; ?>
    
        </ul>
    
    <?php else: ?>
    
       <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
    
    <?php endif; ?>
    </div>

    Boone Gorges
    Keymaster

    @boonebgorges

    You can pass user IDs into bp_has_members() like this:

    
    $custom_ids = my_custom_ids( 'country', 'usa' );
    $has_members_args = array(
        'include' => $custom_ids,
    );
    if ( bp_has_members() ) {
        ...
    }
    

    stunomatic
    Participant

    @stunomatic

    Hi,

    Thanks Boone for replying.

    I did as you said but still this while loop shows all the user profiles.

    If I echo ” echo $custom_ids; ” This shows correct number of ids

    Is there something I need to do with while loop as well ?

    Thanks

    <?php 		
    $contrytoggle = get_field( "country_toggle" );
    $contrypri = get_field( "select_country" ); ?>
    
    <?php echo $contrytoggle; ?>
    
    <?php $custom_ids = my_custom_ids($contrytoggle, $contrypri);
    
      $has_members_args = array(
        'include' => $custom_ids,
    ); 
      
      echo $custom_ids;   // This shows correct number of ids
       
      if ( bp_has_members() ) :
    
     ?> 
      
    	   	<ul>
      <?php while ( bp_members() ) : bp_the_member(); ?>
     
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
     
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
          </div>
    	</li>
    	  
    	   <?php endwhile; ?>
    
    	</ul>
    	
    <?php else: ?>
     
        <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
       
    
    	
    <?php endif; ?>
    </div>
    

    stunomatic
    Participant

    @stunomatic

    If I pass include inside if then,

    echo $contrytoggle; = It shows 4 id’s 6,7,8,9

    and below code show only 3 users… user with 6th ID is missing

    <?php 		
    $contrytoggle = get_field( "country_toggle" );
    $contrypri = get_field( "select_country" ); ?>
    
    <?php echo $contrytoggle; ?>
    
    <?php $custom_ids = my_custom_ids($contrytoggle, $contrypri);  
    
     // $has_members_args = array(
       // 'include' => $custom_ids,
    // ); 
      
      echo $custom_ids; 
       
      if ( bp_has_members( 'include=' . $custom_ids ) ) :
    
     ?> 
      
    	   	<ul>
      <?php while ( bp_members() ) : bp_the_member(); ?>
     
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
     
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
          </div>
    	</li>
    	  
    	   <?php endwhile; ?>
    
    	</ul>
    	
    <?php else: ?>
     
        <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
       
    
    	
    <?php endif; ?>
    </div>
    

    stunomatic
    Participant

    @stunomatic

    I am back to start. If there id’s it shows only specific ids but if its null then it shows all the users :s

    <?php 		
    $contrytoggle = get_field( "country_toggle" );
    $contrypri = get_field( "select_country" ); ?>
    
    <?php echo $contrytoggle; ?>
    
    <?php $custom_ids = my_custom_ids($contrytoggle, $contrypri);  
    
     // $has_members_args = array(
       // 'include' => $custom_ids,
    // ); 
      
      echo $custom_ids;   // it echo no id and still it shows all the users 
       
      if ( bp_has_members( $custom_ids )  ) :
    
     ?> 
      
    	   	<ul>
      <?php while ( bp_members() ) : bp_the_member(); ?>
     
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
     
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
          </div>
    	</li>
    	  
    	   <?php endwhile; ?>
    
    	</ul>
    	
    <?php else: ?>
     
        <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
       
    
    	
    <?php endif; ?>
    </div>
    
        

    stunomatic
    Participant

    @stunomatic

    Any Help ?


    stunomatic
    Participant

    @stunomatic

    Anyone ?


    stunomatic
    Participant

    @stunomatic

    Guys can you help me out with this one. I tried all your methods and it is still showing all members if non selected.

    Thanks


    georgeseybold
    Participant

    @georgeseybold

    /* Following this post */

    Would like to to the same with State and City.


    elliotyamoah
    Participant

    @elliotyamoah

    Hi, I hope this is still on topic. Here is another feature request that I need for my site. I’m looking for something like a cross-domain member type. In this case the activity feed from one BuddyPress site would feature on another BuddyPress site. Members would be filtered out by whether they have a local account or an account synchronized from another BuddyPress site.

    Please check out the post here

    Extended Community

    Thank you

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Skip to toolbar