-
AuthorSearch Results
-
June 19, 2019 at 12:33 pm #214457
In reply to: using string to translate text in within filter
AnonymousInactiveI have found this however it as sfid ==12345 what do you use to replace 12345? Would this be a more correct snippet.
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);
June 19, 2019 at 11:20 am #214449In reply to: using string to translate text in within filter
TrevorParticipantI think you need to take a look at some of the snippets shown in this search:
https://support.searchandfilter.com/forums/search/sf_input_object_pre+label+option/
June 19, 2019 at 9:56 am #214427In reply to: using string to translate text in within filter
AnonymousInactiveI am trying this code from the documentation you supplied. However it just removes all the options.
How can I use this correctly?<?php function filter_input_object($input_object, $sfid) { foreach($input_object['options'] as $option) { if($option->value=="brochures") {//the option with no value is always the "all items" or unselected state $option->label = "Brochures"; } else if($option->value=="brochures") {//we want to change the label for the option "black" - we can feed back in the count number to the label for this field type $option->label = "test (".$option->count.")"; } } } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2); ?>
April 10, 2019 at 8:32 pm #208110
AnonymousInactiveI managed to pull the term in by using the
sf_input_object_pre
hook so find the search field and check if the value was empty. On my site, the only way to get to the search results page is from the header search so they should always arrive with a search term. So by getting the term from$wp->query_vars['s']
, it will fill it into the shortcode form before it renders the first time on the results page.I’m still having some funky issues though – like the logo on my site is a link to the homepage on every page that is NOT the homepage. But since is_home is now true on the search results page despite that I’m forcing the is_search from the plugin options, I had to edit my logo so it would be a link if it was search with
is_search
. So far so good. Thank you for all your patience. Much appreciated.March 28, 2019 at 3:46 pm #206792In reply to: Dropdown 'author' taxonomy showing empty options
AnonymousInactiveTrevor, you are awesome! Thanks for troubleshooting again. Would not have arrived at this on my own.
FINAL code:
function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sft_author') { global $coauthors_plus; foreach($input_object['options'] as $key => $option) { if($option->value=="") { $option->label = "Search by Author"; } else { $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value ); if ($user->display_name=='') { unset($input_object['options'][$key]); } else { $input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')'; } } } } return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
March 27, 2019 at 3:24 pm #206571
AnonymousInactiveFINAL code:
Okay, so the code required included that original bit. Here is the final code in the inc/template-tags.php file:
if ( ! function_exists( 'visual_posted_on' ) ) : /** * Integrate Co-Authors Plus with TwentyTen by replacing twentyten_posted_on() with this function */ function visual_posted_on() { if ( function_exists( 'coauthors_posts_links' ) ) : printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), 'meta-prep meta-prep-author', sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), coauthors_posts_links( null, null, null, null, false ) ); else: printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), 'meta-prep meta-prep-author', sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ), get_the_author() ) ); endif; } endif; function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sft_author') { global $coauthors_plus; foreach($input_object['options'] as $key => $option) { if($option->value=="") { $option->label = "Search by Author"; } 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);
Also, added Relevanssi plugin per your guidance and enabled it within SF Pro search form > Advanced settings.
Really appreciate your continued support on this issue! Glad to have it resolved now.
March 26, 2019 at 1:35 pm #206324
AnonymousInactiveOkay, so that code it still not working for me. I added it just beneath my original code. See below:
if ( ! function_exists( 'visual_posted_on' ) ) : /** * Integrate Co-Authors Plus with TwentyTen by replacing twentyten_posted_on() with this function */ function visual_posted_on() { if ( function_exists( 'coauthors_posts_links' ) ) : printf( __( '%2$s <span style="color:#999;">/</span> %3$s', 'visual' ), 'meta-prep meta-prep-author', sprintf( '<span class="entry-date">%3$s</span>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), coauthors_posts_links( null, null, null, null, false ) ); else: printf( __( '%2$s <span style="color:#999;">/</span> %3$s', 'visual' ), 'meta-prep meta-prep-author', sprintf( '<span class="entry-date">%3$s</span>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), esc_attr( sprintf( __( 'View all posts by %s', 'visual' ), get_the_author() ) ), get_the_author() ) ); endif; } endif; function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sft_author') { global $coauthors_plus; foreach($input_object['options'] as $key => $option) { if($option->value=="") { $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);
Should I remove the first part of that code and only have the part you gave me?
The “All Authors” dropdown is still not recognizing additional authors, i.e. Wael (only ones in the first position on a post). And the search field is not recognizing them either. Thanks again for your quick responses.
March 26, 2019 at 1:13 pm #206312
TrevorParticipantOk, so it must go in the file you suggested.
The only bock of code you would have need to add was this, I think:
function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sft_author') { global $coauthors_plus; foreach($input_object['options'] as $key => $option) { if($option->value=="") { $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);
The question is, is that code working? Does the field show ‘All Authors’ in the choice box?
If so, if you edit just that one line to change that label, does it then change in the front end?
March 26, 2019 at 12:37 pm #206286
AnonymousInactiveThanks for your quick response, Trevor. However, I had tried that solution before posting here and it did not work for me. I’m using a child of the Visual Theme. When adding the CoAuthors plugin to the site, this was the code I added into my template-tags.php file in my child theme:
if ( ! function_exists( 'visual_posted_on' ) ) : /** * Integrate Co-Authors Plus with TwentyTen by replacing twentyten_posted_on() with this function */ function visual_posted_on() { if ( function_exists( 'coauthors_posts_links' ) ) : printf( __( '%2$s <span style="color:#999;">/</span> %3$s', 'visual' ), 'meta-prep meta-prep-author', sprintf( '<span class="entry-date">%3$s</span>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), coauthors_posts_links( null, null, null, null, false ) ); else: printf( __( '%2$s <span style="color:#999;">/</span> %3$s', 'visual' ), 'meta-prep meta-prep-author', sprintf( '<span class="entry-date">%3$s</span>', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), esc_attr( sprintf( __( 'View all posts by %s', 'visual' ), get_the_author() ) ), get_the_author() ) ); endif; } endif;
Then, I added the Trial by Fire code after:
// 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);
But still no dice. I’m not sure what I’m missing here, but what should be happening is that when I search for Wael in the search box or even in the dropdown Authors box he should be appearing. But he is not. I would appreciate any further help you can provide. I am stumped.
March 22, 2019 at 11:27 am #205996Topic: Custom A-Z
in forum Search & Filter Pro
AnonymousInactiveHi, I have a requirement for a search to select posts (staff members) from their second name letter.
So a list of radio inputs – A B C D… Z
When you click on a letter it would filter the post search and only show people who’s second name begin with that letter.
I’m sure this is possible but please can you point in the right direction!
I have been looking at the
sf_input_object_pre
filterThis seems like the correct one to use.
-
AuthorSearch Results
-
Search Results
-
Topic: Custom A-Z
Hi, I have a requirement for a search to select posts (staff members) from their second name letter.
So a list of radio inputs – A B C D… Z
When you click on a letter it would filter the post search and only show people who’s second name begin with that letter.
I’m sure this is possible but please can you point in the right direction!
I have been looking at the
sf_input_object_pre
filterThis seems like the correct one to use.