Answer the question
In order to leave comments, you need to log in
How to get body class from wp_termmeta?
Wordpress
There is a table wp_termmeta with cells meta_id, term_id, meta_key, meta_value It is
necessary to display the meta_value value as a css class in the body_class
Google led to this:
// add taxoonomy term to body_class
function lalka_custom_taxonomy_in_body_class( $classes ){
if( is_singular() )
{
$custom_terms = get_term_meta($meta_id, 'custom-class', true );
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'custom-tax-' . $custom_term->slug;
}
}
}
return $classes;
}
add_filter( 'body_class', 'lalka_custom_taxonomy_in_body_class' );
Answer the question
In order to leave comments, you need to log in
Issue resolved! In case anyone needs it:
add_filter( 'body_class', 'lalka_custom_taxonomy_in_body_class' );
function lalka_custom_taxonomy_in_body_class( $classes ){
if (is_tax('product_cat')) {
$custom_class = !empty( get_queried_object_id() ) ? get_term_meta(get_queried_object_id(), 'custom-class', true) : FALSE;
if ( !empty($custom_class) ) {
$classes[] = 'custom-tax-' . $custom_class;
}
}
return $classes;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question