php - Loop through post member categories, check if desendant of x (by name) -
i'm using wordpress woocommerce, on single product page want check if 1 of product member categories member of parent 'brands' , if display description brand member category.
i've done following, outputs categories product member of;
<?php $terms = get_the_terms( $post->id, 'product_cat' ); if($terms){ foreach($terms $term){ $category_parent_id = $term->parent; $category_parent = get_category($category_parent_id); $category_description = $term->description; //if(($category_parent = "brands")){ // doesnt work outputs cats if( "brands" == $category_parent ){ // doesnt work either, outputs no results $category_name = $term->name; $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); $image = wp_get_attachment_url($category_thumbnail); ?> html stuff here <?php } } } ?> brands > brands > brand1 > brands > brand1 > product brands > brand2 > brands > brand2 > product brands > brand9999 > brands > brand9999 > product
if 'product' member of 'brandx' member of 'brands' output description 'brandx' category.
hi have typo
if(($category_parent == "brands")){ // doesnt work
that why it's change place put primitives left side
if( "brands" == $category_parent ){ }
Comments
Post a Comment