带有redis对象缓存问题的get_terms

发布于 2025-02-10 17:18:36 字数 561 浏览 2 评论 0原文

默认情况下,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>';
}

By default, hide_empty => is set to be true. If Redis object cache is disabled, the below code works just fine. But when Redis is enabled, the empty term will not be hidden. It just shows all the terms. I have tried to flush the cache. The issue remains.

Any idea what may cause the issue? thanks

$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>';
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦亿 2025-02-17 17:18:36

我设法用学期计数解决了

$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>';
}

I managed to solve it with 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>';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文