-
AuthorSearch Results
-
February 23, 2018 at 9:10 am #161666
In reply to: ACF-taxonomy field showing term ids not term names
AnonymousInactiveI solved the problem using the ‘sf_input_object_pre’ filter:
add_filter('sf_input_object_pre', 'pas_filterlabels_aan', 10, 2); function pas_filterlabels_aan($input_object, $sfid) { if($input_object['name'] == '_sfm_vakdomein') { foreach($input_object['options'] as $option) { $term_id = $option->value; if ($option->value) { $term = get_term_by('id', $term_id, 'cursussoort'); $term_label = $term->name; $option->label = $term_label.' ('.$option->count.')'; } } } return $input_object; }
Replace ‘_sfm_vakdomein’ by your input object name (is shown in the query string) and ‘cursussoort’ by your taxonomy slug.
January 12, 2018 at 7:18 pm #152293In reply to: Sort Author dropdown by Last Name
AnonymousInactiveOK Here it is. I needed to show the author name by last, first, and sometimes the username by last,first. So I have a hook (which yes, you put in functions.php) and I check the form id and the field we’re outputting, and process it based on what the values are.
If we’re looking at the author field, i basically requery the entire author list, and regenerate the list completely. You can see I exclude some authors (like admin, and some other random people i didn’t want in the list)
If it’s the user field, i do a loop and requery the user and then adjust the info.
I think i wrote the two if statements at different times, because the second way could probably be applied to the first. Whatever, it works.
function sf_edit_author_field_order($input_object, $sfid) { if( in_array( $sfid, array( 3390, 3444, 3562 ) ) && $input_object['name'] == '_sf_author' ) { // requery the author list $author_args = array( 'exclude_admin' => true, 'hide_empty' => true, 'meta_key' => 'last_name', 'orderby' => 'meta_value', 'order' => 'ASC', 'exclude' => array( 429, 233, 558, 7 ) ); $user_query = new WP_User_Query( $author_args ); $users = $user_query->get_results(); $new_users = array(); $new_users[] = (object) array( 'label' => 'All Authors', 'attributes' => array ( 'class' => 'sf-level-0 sf-item-0' ), 'value' => '', 'count' => 0 ); // go through users and get their user_nicename and display_name foreach( $users as $user ) { $new_users[] = (object) array( 'attributes' => array( 'class' => 'sf-level-0' ), 'value' => $user->user_nicename, 'label' => $user->last_name . ', ' . $user->first_name, 'count' => 1 ); } $input_object['options'] = $new_users; } else if ( $sfid == 3444 && $input_object['name'] == '_sft_userlist' ) { // requery the tagged user list to get their names - last, first // go through the options part of the object and get the user id, and then the meta info for that foreach ($input_object['options'] as $option) { // get the user id from the term meta $temp_term = get_term_by( 'slug', $option->value, 'userlist'); $temp_term->meta_user_id = get_term_meta( $temp_term->term_id, 'user_id', true ); $last_name = get_user_meta( $temp_term->meta_user_id, 'last_name', true ); $first_name = get_user_meta( $temp_term->meta_user_id, 'first_name', true ); // overwrite the original label if ( $last_name && $first_name ) { $option->label = $last_name . ', ' . $first_name; } } } return $input_object; } add_filter('sf_input_object_pre', 'sf_edit_author_field_order', 10, 2);
April 27, 2017 at 12:58 am #105123In reply to: Range Select: Add value at the beginning (text)
RossKeymasterHi Javier
You can do this with the current version..
Take a look at the docs here:
Nearly any value in any input object can be changed if you dig deep enough into the
$input_object
there are all kinds of things that can be changed.Tested locally, and updated to match your field name
_sfm_precio
, this should do the trick:function filter_range_dropdown($input_object, $sfid) { if($input_object['name']=='_sfm_precio') { //udpate this field before rendering //if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) if(!isset($input_object['options'])) { return $input_object; } //now loop through the options in the field foreach($input_object['options'] as $option) { //update every label, and prefix and suffix with $ $option->label = "$ ".$option->label." $"; } } //always return the input object, even if we made no changes return $input_object; } add_filter('sf_input_object_pre', 'filter_range_dropdown', 10, 2);
Hope that helps
January 14, 2017 at 1:13 pm #82378Topic: No longer searching
in forum Search & Filter Pro
AnonymousInactiveAll of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/
Tweaks to code as per previous threads here:
// Search Filter function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) { $new_options = array(); //the options added to this will replace all existing optoins in the field foreach($input_object['options'] as $option) { if ($option->value !== "") { //check to see if the option has a parent $parent_id = wp_get_post_parent_id($option->value); if(!$parent_id) { //then this option does not have a parent, so it must be a parent itself, add it to the new array $option->label = get_the_title($option->value); array_push($new_options, $option); } } } //now we have an array with only parent options in, so simply replace the one in the input object $input_object['options'] = $new_options; } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Any ideas?
August 1, 2016 at 8:51 am #52893In 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);
-
AuthorSearch Results
-
Search Results
-
Topic: No longer searching
All of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/
Tweaks to code as per previous threads here:
// Search Filter function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) { $new_options = array(); //the options added to this will replace all existing optoins in the field foreach($input_object['options'] as $option) { if ($option->value !== "") { //check to see if the option has a parent $parent_id = wp_get_post_parent_id($option->value); if(!$parent_id) { //then this option does not have a parent, so it must be a parent itself, add it to the new array $option->label = get_the_title($option->value); array_push($new_options, $option); } } } //now we have an array with only parent options in, so simply replace the one in the input object $input_object['options'] = $new_options; } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Any ideas?