Skip to content

Instantly share code, notes, and snippets.

@jonwatson87
Last active July 8, 2016 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonwatson87/529e23a7db73fc906e784b098ccc8cfa to your computer and use it in GitHub Desktop.
Save jonwatson87/529e23a7db73fc906e784b098ccc8cfa to your computer and use it in GitHub Desktop.
Relabel author names from Login to Last Name, First Name when displaying Co-Authors Pro as a taxonomy in Search & Filter Pro Raw, and sort by the new label
// 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 . ')';
}
}
// Sort options...
$sortArray = array();
foreach($input_object['options'] as $option) {
foreach($option as $key => $value) {
if(!isset($sortArray[$key])) {
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
// ...by label
$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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment