WordPress 竟然没有一个根据 $term_id
获取分类模式 taxonomy 的函数,那就自己写一个:
function get_term_taxonomy($id){
$term = get_term($id);
return ($term && !is_wp_error($term)) ? $term->taxonomy : null;
}
这样在其他代码中就方便调用了,并且还处理了返回是 WP_Error
的情况。 😁
哪一天如果 WordPress 自己也支持了?那就加上 function_exists
的判断:
if(!function_exists('get_term_taxonomy')){
function get_term_taxonomy($id){
$term = get_term($id);
return ($term && !is_wp_error($term)) ? $term->taxonomy : null;
}
}
好,非常完美,加入 WPJAM Basic,下一版本上线的时候,就有该函数了。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有