Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress Field On Member loop – Need Links


  • penfao
    Participant

    @penfao

    Hi.

    I’ve change my member-loop.php file so that some field appear :

    <?php if ( bp_get_member_profile_data( 'field=Country' ) ) : ?>
         <?php echo bp_member_profile_data( 'field=Country' ); ?>

    What I need now is this field to be linked. I mean I want this to be clickable and when someone lick on it, it redirect to users directory and show every users who have the same Country in ‘ Country Field ‘. It’s working on single profile page but not in Member loop.

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

  • shanebp
    Moderator

    @shanebp

    Try:
    $href = site_url() . '/members/?s=' . bp_member_profile_data( 'field=Country' ) . '&members_search_submit=Search';


    penfao
    Participant

    @penfao

    sorry I’m new in php.

    You mean

    <?php if ( $href = http://www.mysite.com() . '/members/?s=' bp_get_member_profile_data( 'field=Country' ). '&members_search_submit=Search'; ) : ?>

    ?


    shanebp
    Moderator

    @shanebp

    <?php 
    $country = bp_get_member_profile_data( 'field=Country' );
    if ( $country != false ) {
        
        $href = site_url() . '/members/?s=' . $country . '&members_search_submit=Search';
    
        echo '<a href="' . $href . '">' . $country . '</a>';
    }
    ?>

    penfao
    Participant

    @penfao

    Thanks ! It’s clickable now but the link goes to 404 error


    penfao
    Participant

    @penfao

    Ok. I just solve it. Thanks again !


    danbp
    Moderator

    @danbp

    Here’s another approach, as we going to use an external function instead of modifying the template.

    Add this to bp-custom.php

    function clickable_countries_on_member_directory() {	
    // is xprofile component active ?
    if ( bp_is_active( 'xprofile' ) ) {
    
    	if ( $mycountry = xprofile_get_field_data( 'Country', bp_get_member_user_id() ) ) :
    		$search_url   = add_query_arg( array( 's' => urlencode( $mycountry ) ), bp_get_members_directory_permalink() );
    		echo '<br/><div class="my_country"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $mycountry . '</a></div>';
    	endif;	
    
    	}
    }
    add_filter ( 'bp_directory_members_item', 'clickable_countries_on_member_directory' );

    penfao
    Participant

    @penfao

    thanks.
    Now it’s working but for one field I’m using multiselector field,
    so when I click, it search for the 2 jobs at the same. What I would like is to search for only 1 job at the time


    penfao
    Participant

    @penfao

    Any solution ?


    danbp
    Moderator

    @danbp

    Try this (untested)

    function clickable_job_on_member_directory() {
    	if ( bp_is_active( 'xprofile' ) ) {
    		$user_id = bp_get_member_user_id();
    		$myjob = xprofile_get_field_data( 'Job', $user_id );	
    
    	if ( $myjob == 'vendor' ) :
    		$search_url   = add_query_arg( array( 's' => urlencode( $myjob ) ), bp_get_members_directory_permalink() );
    		echo '<br/><div class="my_job"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $myjob . '</a></div>';
    	endif;	
    
    	if ( $myjob == 'analyst' ) :
    		$search_url   = add_query_arg( array( 's' => urlencode( $myjob ) ), bp_get_members_directory_permalink() );
    		echo '<br/><div class="my_job"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $myjob . '</a></div>';
    	endif;
    
    	if ( $myjob == 'secretary' ) :
    		$search_url   = add_query_arg( array( 's' => urlencode( $myjob ) ), bp_get_members_directory_permalink() );
    		echo '<br/><div class="my_job"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $myjob . '</a></div>';
    	endif;
    	}
    }
    add_filter ( 'bp_directory_members_item', 'clickable_job_on_member_directory' ); 

    penfao
    Participant

    @penfao

    thanks. The issue is that in my list there is more than 100 different jobs…


    danbp
    Moderator

    @danbp

    And what is the problem ? Or you add 150 if.... or much simplier, don’t use a list and let each user enter his job manually instead of let him choose it from a list.


    penfao
    Participant

    @penfao

    Ok, I will do the 150 if 😉

    Thank so much again for the help !


    shanebp
    Moderator

    @shanebp

    $myjob = xprofile_get_field_data( 'Job', $user_id );
    
    if ( is_array( $myjob ) ) {
    
      foreach( $myjob as $job ) { 
    
        $search_url   = add_query_arg( array( 's' => urlencode( $job ) ), bp_get_members_directory_permalink() );
        echo '<br/><div class="my_job"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $job . '</a></div>';
      } 
    }
    else { 
        $search_url   = add_query_arg( array( 's' => urlencode( $myjob ) ), bp_get_members_directory_permalink() );
        echo '<br/><div class="my_job"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $myjob . '</a></div>';
    }
    
    

    penfao
    Participant

    @penfao

    I just try your solution shanebp but still goes to

    http://www.mysite.com/?s=JOBA%2C+JobB

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Buddypress Field On Member loop – Need Links’ is closed to new replies.
Skip to toolbar