-
AuthorSearch Results
-
January 4, 2017 at 5:55 pm #79998
In reply to: How to order a dropdown by display count ?
TrevorParticipantSee 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.
July 8, 2016 at 1:05 pm #50568In reply to: Use meta field for taxonomy value display
AnonymousInactiveHey 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);
June 27, 2016 at 2:13 pm #49503In reply to: Use meta field for taxonomy value display
AnonymousInactiveThanks, 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! 🙂
-
AuthorSearch Results