Created
September 28, 2020 18:13
-
-
Save djrmom/bdf62cdceb9c07eb84ff5b4340cf99e6 to your computer and use it in GitHub Desktop.
facetwp use term as css class in layout builder
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 | |
/** 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