-
AuthorSearch Results
-
August 1, 2016 at 8:51 am #52893
In reply to: Translate ACF Labels with Wp Globus / Qtranslate
AnonymousInactiveThanks Ross!
With this filter it’s possible to access to ‘heading’ label? I’ll need something like this:
function filter_function_name($input_object, $sfid) { $input_object['heading'] = apply_filters( 'the_title', $input_object['heading'] ); return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);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! 🙂
June 19, 2016 at 11:45 pm #48864In reply to: Use meta field for taxonomy value display
AnonymousInactiveDone!
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);June 19, 2016 at 11:38 pm #48863In reply to: Use meta field for taxonomy value display
AnonymousInactiveGOT 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!
June 19, 2016 at 11:22 pm #48858In reply to: Use meta field for taxonomy value display
AnonymousInactiveWhoops! Nope, being an idiot. Ignore what I said about input taxonomy. That was a load of old hogswash. Would help if slowed down for a second to realise just how the filter (and the plugin) worked!
Getting closer:
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 ); $input_object['options'][$key]->label = $user->display_name; } } return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);March 21, 2016 at 1:07 pm #40004In reply to: Change Post Type labels
AnonymousInactivePerfect,
I’ve done it… it works great. Thank you!
For someone curious about how to implement this, on your plugin php add the following function:
function my_plugin_search_filter_change_label($input_object, $sfid) { if ($sfid == 12345 && $input_object['name'] == '_sf_post_type') { foreach ($input_object['options'] as $key => $option) { if ($option->label == 'Media') { $input_object['options'][$key]->label = 'Photos'; } } } return $input_object; } add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);Hope it helps.
January 15, 2016 at 2:30 pm #34366In reply to: Filter Dropdown options
RossKeymasterHi Jacob sorry for the delay.
You’re almost there.
First, you have only 1
=in the firstifstatement.So it does the code for every single field – this needs to be changed to a double
==Second, I think likely you got the fieldname wrong – see here on how to get the correct fieldname:
Here is your code updated (and I’m guessing the field name is from meta data, otherwise you need to find the name as link just above:
<?php function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_workshop_location')) { foreach($input_object['options'] as $option) { $option->label = get_the_title($option->value); } return $input_object; } else { return $input_object; } } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2); ?>Thanks
-
AuthorSearch Results