Forums › Forums › Search & Filter Pro › Dropdown 'author' taxonomy showing empty options
Tagged: coauthorsplus
- This topic has 8 replies, 2 voices, and was last updated 5 years, 8 months ago by Trevor.
Viewing 9 posts - 1 through 9 (of 9 total)
-
Anonymous(Private) March 28, 2019 at 1:46 pm #206739
Hi again, this is regarding the CoAuthors Plus plugin and the help you provided previously.
The dropdown is showing empty options (see screenshot here) which when you click on any of the options that only have the count listed, no results show up. Is there anyway to hide these extra empty options?
Here is the code again:
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);
Anonymous(Private) March 28, 2019 at 3:46 pm #206792Trevor, 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);
-
AuthorPosts
Viewing 9 posts - 1 through 9 (of 9 total)