Forums Forums Search Search Results for 'sf_input_object_pre sort'

Viewing 3 results - 11 through 13 (of 13 total)
  • Author
    Search Results
  • #79998

    Trevor
    Participant

    See here in the documentation.

    If you use the filter sf_input_object_pre you get access to the options as an array, so you can order this array however you want.

    You Do have access to the count variable, so you can use this to sort the array with php. But you would need to code this.

    #50568

    Anonymous
    Inactive

    Hey Davide!

    Sorry for the delay – hectic couple of weeks.

    Try this:

    // Relabel Co-Authors in Search & Filter
    
    	function filter_function_name($input_object, $sfid) {
    
    		if ($input_object['name'] == '_sft_author') {
    
    			global $coauthors_plus;
    			
    			// Update option labels before rendering
    
    				foreach($input_object['options'] as $key => $option) {
    
    					// Rename "all items" label - this is always the option with no value
    
    					if($option->value=="") {
    
    							$option->label = "All Authors";
    
    						}
    
    					else {
    
    						$user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    
    						$input_object['options'][$key]->label = $user->last_name . ', ' . $user->first_name . ' ' . ' (' . $option->count . ')';
    
    	    			}
    
    	        	}
    
    	        	$sortArray = array(); 
    
    	        	foreach($input_object['options'] as $option) { 
    
    				    foreach($option as $key => $value) { 
    
    				        if(!isset($sortArray[$key])) { 
    
    				            $sortArray[$key] = array(); 
    
    				        } 
    
    				        $sortArray[$key][] = $value; 
    
    				    }
    
    				}
    
    	        	$orderby = "label";
    
    				array_multisort($sortArray[$orderby],SORT_ASC,$input_object['options']); 
    
    		}
    		
    		// Return
    
    			return $input_object;
    
    	}
    
    	add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    #49503

    Anonymous
    Inactive

    Thanks, Ross! 🙂

    Sorry, Davide! I haven’t had a chance to look at this yet. Work got kinda busy. Bleurrrrgh!

    As far as putting the last name first bit goes, that’s easy. All you have to do is change display_name to a combination of last_name, first_name. The code would look something like this:

    // Relabel Co-Authors in Search & Filter
    
    	function filter_function_name($input_object, $sfid) {
    
    		if ($input_object['name'] == '_sft_author') {
    
    			global $coauthors_plus;
    			
    			// Update option labels before rendering
    
    				foreach($input_object['options'] as $key => $option) {
    
    					// Rename "all items" label - this is always the option with no value
    
    					if($option->value=="") {
    
    							$option->label = "All Authors";
    
    						}
    
    					else {
    
    						$user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    
    						$input_object['options'][$key]->label = $user->last_name . ', ' . $user->first_name . ' ' . ' (' . $option->count . ')';
    
    	    			}
    
    	        	}
    
    		}
    		
    		return $input_object;
    
    	}
    
    	add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

    As for sorting, I think Ross is right and that the best way to go about it is using one of the standard PHP sorts.

    I’ll have a look at doing that in the next couple of days. Would be a useful one to figure out! 🙂

Viewing 3 results - 11 through 13 (of 13 total)