我试图获取产品的父类别,但实际上它被分配给父类别的子类别,而不是父类别本身。当我为产品分配子类别和父类别时,下面的函数起作用。但我只想将产品分配给子类别,同时显示父类别。按如下顺序:ChildCatName - ParentCatName你能给我指一下正确的方向吗?非常感谢。
//Woo Cat product
$woo_single_cats = get_the_terms( $post->ID, \'product_cat\' );
if ( $woo_single_cats && ! is_wp_error( $woo_single_cats ) ) {
$woo_single_cat = array();
foreach ( $woo_single_cats as $term ) {
$woo_single_cat[$term->term_id] = $term->name;
}
$woo_single_cat = apply_filters(\'seopress_titles_product_cat\', $woo_single_cat);
$woo_single_cat_html = stripslashes_deep(wp_filter_nohtml_kses(join( " - ", $woo_single_cat )));
}
SO网友:MMK
检查它是否适合您。。。我已经修改了循环(loop)$Woo\\u single\\u cats=get\\u the\\u terms($post->;ID,\'product\\u Cat\');
if ( $woo_single_cats && ! is_wp_error( $woo_single_cats ) ) {
$woo_single_cat = array();
foreach ( $woo_single_cats as $term ) {
$woo_single_cat[$term->term_id] = $term->name;
$term_parent_id = $term->parent;
$parent_term = get_term($term_parent_id, \'product_cat\');
}
$woo_single_cat = apply_filters(\'seopress_titles_product_cat\', $woo_single_cat);
$woo_single_cat_html = stripslashes_deep(wp_filter_nohtml_kses(join( " - ", $woo_single_cat )));
}