Forums › Forums › Search & Filter Pro › CoAuthors Plus plugin secondary authors not appearing in search results
Tagged: coauthorsplus
- This topic has 27 replies, 2 voices, and was last updated 5 years, 9 months ago by Trevor.
-
Anonymous(Private) March 25, 2019 at 9:57 pm #206218
Hi, I have
this website that uses the CoAuthors Plus plugin for multiple authors. Example post here. The secondary author listed in this example (Wael) is not associated with the article when searched in the SF Pro search field. In fact, no results show up for Wael. However, you can see under Who We Are > Wael’s page that there are precisely two posts that should be displaying within the search results. Is there a particular integration that would resolve this issue. It is happening with other secondary authors as well.
Trevor(Private) March 26, 2019 at 11:00 am #206237I think this thread might help you:
https://support.searchandfilter.com/forums/topic/use-meta-field-for-taxonomy-value-display/
Anonymous(Private) March 26, 2019 at 12:37 pm #206286Thanks 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.
Anonymous(Private) March 26, 2019 at 12:57 pm #206300Normally, yes. However, with this theme in particular, all my functions are passed to this inc/template-tags.php file. When I add the function to functions.php, it breaks the site. Here is the code in functions.php:
<?php require_once( get_stylesheet_directory(). '/inc/template-tags.php' ); function my_theme_enqueue_styles() { $parent_style = 'visual-master-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); add_action( 'widgets_init', 'theme_slug_widgets_init' ); function theme_slug_widgets_init() { register_sidebar( array( 'name' => __( 'Search Sidebar', 'visual-child' ), 'id' => 'sidebar-2', 'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'visual-child' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ) ); } ?>
Trevor(Private) March 26, 2019 at 1:13 pm #206312Ok, 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?
Anonymous(Private) March 26, 2019 at 1:35 pm #206324Okay, 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.
Anonymous(Private) March 26, 2019 at 2:03 pm #206332Okay, I used only the part you gave me. Looks like the “All Authors” dropdown is still in place and functioning as it was before. See page here.
-
AuthorPosts