Forums Forums Search & Filter Pro Use meta field for taxonomy value display

Viewing 10 posts - 21 through 30 (of 37 total)
  • Anonymous
    #50548

    Hi, it’s almost all ok, i just need a little more help for the ordering… i was not able to write the right code, it’s a little bit complicated for my php skill

    Thanks!

    Trevor
    #50551

    Are you able to show us what you have done, or is it too complex to show here? Code must go inside code tags.

    Anonymous
    #50552

    hi, i’ve stopped at the code written here by Jon Watson, what i tried afterwards does not work ad is not the right way (i do not know how to order the search, i know how to do it in php but i am not able to put it in practice).

    Trevor
    #50553

    OK, I think Ross will need to take a look.

    Anonymous
    #50568

    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);
    Anonymous
    #50585

    it works! Thank you so much, i was not able to write down this code, i still need to study a little more 🙂

    Anonymous
    #153320

    I come back on the subject.

    Code proposed by Jon works good, but with a minor flaw: The “All Items” option gets ordered alphabetically like all the Authors names, instead of staying on top of the list as it should.

    Is there a quick workaround for this available? Thanks guys.

    Trevor
    #153322

    Emanuele

    Are you able to send me a live link/URL to your search page so I can take a look?

    Are you using the exact code as above, or your variation? If it is different, can you add your code to the post, between backticks?

    Backtick is the lower case key of tilde (~) next to the “1” (depends on keyboard what the key looks like), but like this:

    backtick your code backtick

    Anonymous
    #153337
    This reply has been marked as private.
    Trevor
    #153434

    Does the code you use still have this line?

    $option->label = "All Authors";

    or did you change this to:

    $option->label = "Tutti gli Autori";

    If you DID make this change, what happens if you instead comment out this line?

Viewing 10 posts - 21 through 30 (of 37 total)