Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding new ‘Order By’ Options to search group using group custom field.


  • sanjaynakate
    Participant

    @sanjaynakate

    i have added some custom field in group when group is creating this field’s store properly and displaying on group header properly suppose some group have this value “Art and Culture” inserted from custom field. so now have added option in order by like “Art and Culture” if user select this option filter will display the group which have this value “”Art and Culture”

    Bellow is the code i have added option in order by options.

    <?php 
    function antares_groups_filter_options() {
        //echo '<option value="user-league">User League</option>';  
    	echo '<option value="Art and Culture">Art and Culture</option>';
    }
    add_action( 'bp_groups_directory_order_options', 'antares_groups_filter_options' );
    
    function antares_ajax_querystring( $query_string, $object ) {
    
    	if ( 'groups' != $object ) 
    		return $query_string;
    
    	if ( ! bp_is_groups_directory() ) 
    		return $query_string;
    	
    	$query_args = wp_parse_args( $query_string, array() );
    
            $page = $query_args['page'];
    
    	if( isset( $query_args['action'] ) && $query_args['action'] == 'Art and Culture' ) {
    	
    		$query_args = array();
    		$query_args['page'] = $page;
    		$query_args['orderby'] = 'Art and Culture';		
    		$query_args['order'] = 'ASC';
            //$query_args['value'] = 'Art and Culture';		
    		$query_args['include'] = antares_get_groups(); 
    		$query_string = http_build_query( $query_args );
    
    	}
    
    	return $query_string;
    
    }
    add_filter( 'bp_ajax_querystring', 'antares_ajax_querystring', 32, 2 );
    
    function antares_get_groups() {
    
        // put your custom sql here
        // return a csv string of the groups ids
        // for example '1,22,57'
    
    } ?>

    For adding the custom fields in group i have used bellow code

    <?php
     //group custom field
    /**
     *
     *
     * This file defines and implements custom group fields for Great Books Great Discussions.
     *
     *  
     */
     
    function custom_field($meta_key='') {
            //get current group id and load meta_key value if passed. If not pass it blank
            return groups_get_groupmeta( bp_get_group_id(), $meta_key) ;
    }
     
    //code if using seperate files require( dirname( __FILE__ ) . '/buddypress-group-meta.php' );
    // This function is our custom field's form that is called in create a group and when editing group details
    function group_header_fields_markup1() {
            global $bp, $wpdb;?>
     
           
           
     
            <label for="group-custom-field-city">City</label>
            <input id="group-custom-field-city" type="text" name="group-custom-field-city" value="<?php echo custom_field('group-custom-field-city'); ?>" />       
              
    		  <label for="group-custom-field-cat">Category</label>
              <select name="group-custom-field-cat" id="group-custom-field-cat">
    	      <option value="Animal Welfare">Animal Welfare</option>	  
               <option value="Art and Culture">Art and Culture</option>
               <option value="Clean City">Clean City</option>
               <option value="Clean Lake">Clean Lake</option>
               <option value="Education">Education</option>
               <option value="Elderly Care">Elderly Care</option>
               <option value="Energy Conservation">Energy Conservation</option>
               <option value="Environment">Environment</option>
               <option value="Fun and Recreation">Fun and Recreation</option>
               <option value="Health and Medical">Health and Medical</option>
               <option value="Industrial Development">Industrial Development</option>
               <option value="Infrastructure Development">Infrastructure Development</option>
               <option value="Poverty Eradication">Poverty Eradication</option>
               <option value="Social Development">Social Development</option>
               <option value="Sports">Sports</option>
               <option value="Substance Abuse / Addiction">Substance Abuse / Addiction</option>
               <option value="Women's Issues/ Gender Equality">Women's Issues/ Gender Equality</option>
      
    </select>
         <label for="group-custom-field-city-be-fore">Before</label>
         <input type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" /> 
    <label for="group-custom-field-city-af-ter">After</label>
         <input type="file" name="uploadfiles1[]" id="uploadfiles1" size="35" class="uploadfiles" />  	 
            <br>
     
    <?php }
    
    function group_header_fields_save1( $group_id ) {  
    	
           
            global $bp, $wpdb;
     
            $plain_fields = array(
           
                 
                    'group-custom-field-city',
    				'group-custom-field-cat',
    				'group-custom-field-after',
    				'group-custom-field-before',
    				
                   
           
            );
     
            foreach( $plain_fields as $field ) {
           
                    $key = $field;
                   
                    if ( isset( $_POST[$key] ) ) {
           
                            $value = $_POST[$key];
           
                            groups_update_groupmeta( $group_id, $field, $value );
                    }
            }
    }
     
    add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup1' );
    add_action( 'groups_group_details_edited', 'group_header_fields_save1' );
    add_action( 'groups_created_group',  'group_header_fields_save1' );
             
    // Show the custom field in the group header
    function show_field_in_header( ) {
           
            echo "<p>City:" . custom_field('group-custom-field-city') . "</p>";
    		  echo "<p>Category:" . custom_field('group-custom-field-cat') . "</p>";
    		   //echo "<p>After:" . custom_field('group-custom-field-after') . "</p>";
    		   echo "<p>Before:</p>";
    			 echo "<img src='". custom_field('group-custom-field-before') ."'/>";
    			 echo "<p>After:</p>";
    			  echo "<img src='". custom_field('group-custom-field-after') ."'/>";
       
    }
     
    add_action('bp_group_header_meta' , 'show_field_in_header') ; ?>

    can any body help me to achieve this.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Adding new ‘Order By’ Options to search group using group custom field.’ is closed to new replies.
Skip to toolbar