BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 5
    cobe on #31128

    Thank you!

  • Participant
    Level: Initiated
    Posts: 5
    cobe on #31079

    Hi again, i added form for search buddypress to make filtring by city and many more… here is my code:

    
    if ( is_user_logged_in() ) { 
    
    do_action( 'bp_before_members_loop' ); ?>
    
    <div class="container">
    	<form action="" method="get" id="search-members-form">
    	<div class="row">
    		
    		<div class="form-group col-sm-12 col-md-4 col-lg-4">
    			<?php
    			$field_id = 94;
    			$field    = new  BP_XProfile_Field( $field_id );
    			$options  = $field->get_children();
    			echo "<option value=''>Selectioner un Domaine d'activité</option>";
    			foreach ( $options as $option ) {
    				echo '<option value="' . esc_attr( $option->name ) . '">' . esc_html( $option->name ) . '</option>';
    			}
    
    			echo '</select>'; ?>
    		</div>
    		
    		<div class="form-group col-sm-12 col-md-4 col-lg-4">
    			<?php
    			//Select City
    			$field_id = 103;
    			$field    = new  BP_XProfile_Field( $field_id );
    			$options  = $field->get_children();
    			echo "<select name='kechweb-city'  class='mdb-select md-form' searchable='Search here..'>";
    			
    			foreach ( $options as $option ) {
    				echo '<option value="' . esc_attr( $option->name ) . '">' . esc_html( $option->name ) . '</option>';
    			}
    
    			echo '</select>'; 
    			
    			?>
    		</div>
    		
    		<div class="form-group col-sm-12 col-md-4 col-lg-4">
    		<input type="text" name="members_search" id="members_search" placeholder="search company name" />
    		<input type="submit" id="members_search_submit" name="members_search_submit" value="Search">
    		</div>
    		
    	</div>
    	</form>
    </div>
    <?php } ?>
    

    I got the slug page with form methode GET like that :
    ?kechweb-domaine=Construction&kechweb-city=NewYork&members_search=&members_search_submit=Search
    Search doesn’t work maybe I need to add

    if(!empty($_POST['kechweb-domaine']) && !empty($_POST['kechweb-city'])){
    
    }
  • Participant
    Level: Initiated
    Posts: 5
    cobe on #31037

    Thank you so much Brajesh well done!
    Now i want to get value selected and use it for filtring search like: select option Contry and select job of member with form search.

    
    <?php
    		$field_id = 94; // field 
    		$field    = new  BP_XProfile_Field( $field_id );
    		$options  = $field->get_children();
    		echo "<select name='brajesh-Country'>";
    		echo "<option value=''>Select country</option>";
    		foreach ( $options as $option ) {
    			echo '<option value="' . esc_attr( $option->name ) . '">' . esc_html( $option->name ) . '</option>';
    		}
    
    		echo '</select>';
    
    		//Select City
    		$field_id = 103;
    		$field    = new  BP_XProfile_Field( $field_id );
    		$options  = $field->get_children();
    		echo "<select name='brajesh-city'>";
                    echo "<option value=''>Select Job name</option>";
    		foreach ( $options as $option ) {
    			echo '<option value="' . esc_attr( $option->name ) . '">' . esc_html( $option->name ) . '</option>';
    		}
    
    		echo '</select>'; 
    		
    		?>
                <div class="row">
    
    		<div id="brajesh-search-company" class="col-sm-12 col-md-12 col-lg-12">
    			<div id="members-dir-search-company" class="dir-search" role="search">
    				<?php bp_directory_members_search_form(brajesh_custom_ids( 'company_name_field' 
                     )); ?>
    			</div><!-- #members-dir-search -->
    		</div>
    			
    	  </div>
    
    <?php
    function brajesh_custom_ids( $field_name, $field_value = '' ) {
      
      if ( empty( $field_name ) )
        return '';
      
      global $wpdb;
      
      $field_id = xprofile_get_field_id_from_name( $field_name ); 
     
      if ( !empty( $field_id ) ) 
        $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;
      else
       return '';
      
      if ( $field_value != '' ) 
        $query .= " AND value LIKE '%" . $field_value . "%'";
          
        // $query .= " AND value = '" . $field_value . "'"; 
          
    	$custom_ids = $wpdb->get_col( $query );
      
      if ( !empty( $custom_ids ) ) {
        // convert the array to a csv string
        $custom_ids_str = 'include=' . implode(",", $custom_ids);
        return $custom_ids_str;
      }
      else
       return '';  
    }
    ?>
    

    Thank you again

  • Participant
    Level: Initiated
    Posts: 5
    cobe on #30963

    I have xprofile COUNTRY FIELD wish has list like that : (USA, Canada, GBR) and i want to print all data in listbox.
    this is exemple that i want:

    `<select>
    <option value=”USA”>USA</option>
    <option value=”Canada”>Canada</option>
    </select>`

    Note: I fill COUNTRY FIELD FROM administration->users->profile_field->Country_field_name

  • Participant
    Level: Initiated
    Posts: 5
    cobe on #30951

    First of all thank you Brajesh for your help.
    I tried your code i got all fields from xprofile, i want just to get all data saved from specific field called domaine (whish has list of activity like: architetural, science computer etc…)

    This is the code :

     $profile_fields = array();
    
    		$groups = bp_xprofile_get_groups(
    			array(
    				'hide_empty_groups' => true,
    				'fetch_fields'      => true,
    			)
    		); ?>
    		<select>
    		<?php
    		foreach ( $groups as $group ) {
    			foreach ( $group->fields as $field ) {
    				$profile_fields[ $field->id ] = $field->name; ?>
    				<option><?php echo $field->name;; ?></option>
    				<?php
    				
    			}
    		} ?>
    		</select>