Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link

Dilip7597 commented Jun 23, 2019

@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
You can’t perform that action at this time.