get_terms与Redis对象缓存的问题



默认情况下,hide_empty =>设为真。如果Redis对象缓存被禁用,下面的代码工作得很好。但是当Redis被启用时,空项将不会被隐藏。它只是显示了所有的项。我已尝试刷新缓存。

知道可能会导致什么问题吗?由于

$parentid = 182;
$args = array(
'parent' => $parentid
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li>';
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
echo $term->name;
echo '</a>';
echo '</li>';
}
echo '</ul>';
}

我设法用term count来解决它

$parentid = 182;
$args = array(
'parent' => $parentid
);
$terms = get_terms( 'product_cat', $args );
$count = count($terms);
if ( $terms ) {
echo '<ul>';
foreach ( $terms as $term ) {
if ($term->count > 0){
echo '<li>';
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
echo $term->name;
echo '</a>';
echo '</li>';
}
}
echo '</ul>';
}

最新更新