首页 > 解决方案 > 列出所有超过 28 个字符的分类

问题描述

我的网站上有一个问题,原因是属性分类过长。有人可以告诉我是否有办法直接在 DB 中查看更长的分类法?我需要查看所有超过 32 个字符的属性分类。

标签: phpwordpresswoocommerceattributestaxonomy

解决方案


if ( !empty( $_GET[ 'testmode' ] ) ) {
    $terms = get_terms();

    $maxlength_terms = array();
    foreach ( $terms as $term ) {
        if ( strlen( $term->name ) > 28 ) {
            $maxlength_terms[] = $term;
        }
    }

    foreach ( $maxlength_terms as $key => $max_term ) {
        $update = wp_update_term( $max_term->term_id, $max_term->taxonomy, array(
            'name' => substr( $term->name, 0, 28 ),
        ) );
    }
}

尝试在您的活动主题 functions.php 中添加它并访问您的网站 URL,例如 www.yoururl.com?testmode=1


推荐阅读