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

Viewing 10 posts - 11 through 20 (of 37 total)
  • Anonymous
    #48863

    GOT IT!

    Just trying to figure out why my “All authors” label is now missing, but the names are showing up properly! Was just missing the “->value” after the $option above:

    function filter_function_name($input_object, $sfid) {
    
    	if ($input_object['name'] == '_sft_author') {
    
    		global $coauthors_plus;
    		
    		//udpate this field before rendering
    
    			foreach($input_object['options'] as $key => $option) {
    
    				$user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    
        			$input_object['options'][$key]->label = $user->display_name;
    
            	}
    
    	}
    	
    	return $input_object;
    
    }
    
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

    Will post back in a few with final code, once I’ve figured out where my main label has gone!

    Anonymous
    #48864

    Done!

    Added back the “All Authors” title and my post count. Final code:

    // Trial by fire
    
    function filter_function_name($input_object, $sfid) {
    
    	if ($input_object['name'] == '_sft_author') {
    
    		global $coauthors_plus;
    		
    		//udpate this field before rendering
    
    			foreach($input_object['options'] as $key => $option) {
    
    				if($option->value=="")
    					{//the option with no value is always the "all items" or unselected state
    						$option->label = "All Authors";
    					}
    
    				else {
    
    				$user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    
        			$input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';
    
        			}
    
            	}
    
    	}
    	
    	return $input_object;
    
    }
    
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    Anonymous
    #48917

    Hi, thanks for the code, honestly i would not be able to do this!

    I try and tell you if it works (but i guess it does)!

    Anonymous
    #48924

    wonderful, it works fine!!! i ask for the last help, if possible, an orderby (last_name or whatever) option in the code

    thanks again

    Anonymous
    #48950

    Awesome! Glad it’s working, Davide! ๐Ÿ˜€

    Is there something specific you wanted to sort by, or were you looking for a few different options?

    And if sorting by last_name, do you need to display your authors last name first? (Something like “Poli, Corrado”?

    Anonymous
    #48957

    hi, thanks for your answer.

    It would be enough to be able to order by last name, and if it is possible to make the name appear with last name for first it would be good too!

    Thanks

    Anonymous
    #49404

    Hi, have you found some way for ordering the query? I tried but no success by now, hope there are good news!

    Thanks for your answer

    Ross Moderator
    #49469

    Hey Davide

    Just to let you know (you probably did already) that Jon is a regular (well, a really helpful..) user.

    You are entering unchartered territory so I don’t have anything to hand that will do what you want, this is all quite custom work really.

    To order the query itself (ie the results), there are options in S&F for this under the “posts” tab – but – what I think you mean is the ordering of the field options, by last name?

    As I mentioned I don’t have anything to hand, but I know what your looking to do is a pure PHP thing really, ordering an array, by the second word in the string of an array value… I did a quick google, and it looks like this can help achieve what you are trying to do:

    http://stackoverflow.com/questions/9370615/how-to-sort-an-array-of-names-by-surname-preserving-the-keys

    Thanks

    Anonymous
    #49503

    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! ๐Ÿ™‚

    Anonymous
    #49504

    Hi, thanks both for your answers ๐Ÿ™‚

    i’ll the code you suggest (i tried with something similar, but was not successfull), if i have news i post here

    thanks again!

Viewing 10 posts - 11 through 20 (of 37 total)