Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created September 28, 2020 18:13
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 djrmom/bdf62cdceb9c07eb84ff5b4340cf99e6 to your computer and use it in GitHub Desktop.
Save djrmom/bdf62cdceb9c07eb84ff5b4340cf99e6 to your computer and use it in GitHub Desktop.
facetwp use term as css class in layout builder
<?php
/** creates a space seperated list of terms (instead of links) for use in
** dynamic tags for outputting a css class
**/
add_action( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'product-categories' == $item['settings']['name'] ) {
$value = "";
$terms = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
foreach ( $terms AS $term ) {
$value .= $term->slug . "";
}
}
}
return $value;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment