Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created August 23, 2017 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/e29a431163e8a343d24b127ec7a0082d to your computer and use it in GitHub Desktop.
Save mgibbs189/e29a431163e8a343d24b127ec7a0082d to your computer and use it in GitHub Desktop.
FacetWP - support for Co-authors Plus
<?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 );
@jonwatson87
Copy link

jonwatson87 commented Oct 24, 2017

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.

@Dilip7597
Copy link

@jonwatson87, you Sir, saved my day. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment