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, 9 months ago by Anonymous.
-
Anonymous(Private) June 19, 2016 at 11:38 pm #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(Private) June 19, 2016 at 11:45 pm #48864Done!
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(Private) June 20, 2016 at 7:17 pm #48950Awesome! 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”?
Ross Moderator(Private) June 26, 2016 at 9:26 pm #49469Hey 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:
Thanks
Anonymous(Private) June 27, 2016 at 2:13 pm #49503Thanks, 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! ๐
-
AuthorPosts