Forums › Forums › Search & Filter Pro › Use meta field for taxonomy value display
Tagged: Co-Authors Plus, post meta, taxonomy
- This topic has 36 replies, 6 voices, and was last updated 6 years, 11 months ago by Anonymous.
-
Anonymous(Private) July 8, 2016 at 1:05 pm #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(Private) January 18, 2018 at 6:16 pm #153320I 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(Private) January 18, 2018 at 6:23 pm #153322Emanuele
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
-
AuthorPosts