Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active July 19, 2018 16:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/ead3af174fe81c2178e3e7962a639725 to your computer and use it in GitHub Desktop.
Save djrmom/ead3af174fe81c2178e3e7962a639725 to your computer and use it in GitHub Desktop.
facetwp add tags to category facet
<?php
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
if ( 'cases_topics' == $params['facet']['name'] ) {
$post_id = $params['defaults']['post_id'];
$tags = get_tags( $post_id );
if ( !empty( $tags ) ) {
foreach ( $tags as $tag ) {
$new_row = $params['defaults'];
$new_row['facet_source'] = 'tax/post_tag';
$new_row['facet_value'] = $tag->slug;
$new_row['facet_display_value'] = $tag->name;
$new_row['term_id'] = $tag->term_id;
$rows[] = $new_row;
}
}
}
return $rows;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment