首先,您需要hydro term的术语id,您可以使用get_term_by
$hydro = get_term_by(\'slug\', \'hydro\', \'product_cat\');
之后,您可以使用术语id作为
\'parent\'
的参数
get_terms
$hydro_children = get_terms( \'product_cat\', array( \'parent\' => $hydro->term_id ) );
现在,您可以显示这些子项的列表:
if ( ! empty($hydro_children) ) {
echo \'<ul>\';
foreach( $hydro_children as $hydro_child ) {
echo \'<li><a href="\' . get_term_link($hydro_child, \'product_cat\') . \'">\';
echo $hydro_child->name . \'</a></li>\';
}
echo \'</ul>\';
}
和/或使用
$hydro_children
附加条款,如果需要,可以跳过只有
$hydro_children
术语(“hydro”的孙子孙女),感谢
\'include_children\'
税务查询参数:
$args = array(
\'post_type\' => \'product\', // I guess
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'id\',
\'terms\' => wp_list_pluck($hydro_children, \'term_id\'),
\'include_children\' => false
)
)
);
$query = new WP_Query( $args );