WordPress函数:category_exists 判断分类是否存在

追格官方小助手/ 2022年08月13日/ WordPress/ 浏览 932

在WordPress中 判断一个分类是否存在,只需要使用 category_exists 函数。


函数源码:


function category_exists( $cat_name, $category_parent = null ) {
    $id = term_exists( $cat_name, 'category', $category_parent );
    if ( is_array( $id ) ) {
        $id = $id['term_id'];
    }
    return $id;
}


从源码中可以看出,使用了函数 term_exists。

term_exists 更加通用,可是检查任意文章类型的分类是否存在。

发表评论

暂无评论,抢个沙发...

客服 工单