使用 get_the_term 获取所有父项和子项
get all parent and children by using get_the_term
我遇到了问题。我一直在寻找以分层形式获取 Parent + 每个 Child 名称(或 slugs)并将其分配给 wordpress 上的每个变量。
我的分类法是这样的:
肥料
-粉状
--p1
--p2
-液体
--l1
--l2
杀虫剂
-粉状
--p1
--p2
-液体
--l1
--l2
我想在单页使用。
感谢您的所有回答
我解决了我的问题:
$cat1 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> 0) );
$cat2 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> $cat1[0]->term_id) );
$cat3 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> $cat2[0]->term_id) );
我遇到了问题。我一直在寻找以分层形式获取 Parent + 每个 Child 名称(或 slugs)并将其分配给 wordpress 上的每个变量。
我的分类法是这样的:
肥料
-粉状
--p1
--p2
-液体
--l1
--l2
杀虫剂
-粉状
--p1
--p2
-液体
--l1
--l2
我想在单页使用。
感谢您的所有回答 我解决了我的问题:
$cat1 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> 0) );
$cat2 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> $cat1[0]->term_id) );
$cat3 = wp_get_object_terms( $post->ID, 'cypress_tax_products', array('parent'=> $cat2[0]->term_id) );