删除 Wordpress 中的特定类别

Remove particular category in Wordpress

我正在尝试使用自定义分类法从自定义 post 中隐藏 "Gyming" 类别。非常努力地尝试得到结果,但不幸的是它不适用于以下代码。

function cat_subcat(){
$thetax = 'product';
    $args = array(
        'taxonomy' => 'product',
        //'parent' => 0,
        'hierarchical'=>true,
        'order'=> 'ASC',
        'show_count'=>false,
        'show_option_all'=>'',
        'child_of'=>0,
        'depth'=>3,
        'title_li'=>'',
        'show_option_none'    => __( 'No categories' ),
    );
echo '<ul class="category">';
    wp_list_categories( $args );
echo '</ul>';

}

请指教。

如果您想从您创建的列表中排除某个类别,您可以将 exclude 添加到您的 args,其中值是您要排除的类别的 ID 数组。因此,如果您希望排除类别 'Gyming',您首先必须找到该类别的 ID。如果您不确定如何查找 ID,请使用以下指南 https://www.wpwhitesecurity.com/wordpress-tutorial/find-wordpress-category-id/

如果 ID 是 42,您的新代码将是

function cat_subcat(){
$thetax = 'product';
    $args = array(
        'taxonomy' => 'product',
        //'parent' => 0,
        'hierarchical'=>true,
        'order'=> 'ASC',
        'show_count'=>false,
        'show_option_all'=>'',
        'child_of'=>0,
        'depth'=>3,
        'title_li'=>'',
        'show_option_none'    => __( 'No categories' ),
        'exclude'    => array( 42 ),
    );
echo '<ul class="category">';
    wp_list_categories( $args );
echo '</ul>';
}