Created
August 23, 2017 02:00
-
-
Save mgibbs189/e29a431163e8a343d24b127ec7a0082d to your computer and use it in GitHub Desktop.
FacetWP - support for Co-authors Plus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add to your (child) theme's functions.php | |
add_filter( 'facetwp_facet_sources', function( $sources ) { | |
if ( class_exists( 'coauthors_plus') && isset( $sources['taxonomies']['choices']['tax/author'] ) ) { | |
$sources['co_authors'] = array( | |
'label' => 'Co-Authors', | |
'choices' => array( | |
'tax/author' => 'Authors' | |
) | |
); | |
} | |
return $sources; | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd also add the following, to ensure that FacetWP shows the Display Name (rather than the Username - which could be a potential security issue):
// Replace Label with Display Name
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'author' == $params['facet_name'] ) {
$raw_value = $params['facet_value']; // cap-nicename
$nicename = substr($raw_value, 4); // nicename
$coauthor = get_user_by('slug',$nicename); // get user data
$params['facet_display_value'] = $coauthor->display_name; // Display Name
}
return $params;
}, 10, 2 );
Where "author" is the slug of your facet.