脚本宝典收集整理的这篇文章主要介绍了php – 如何检查类别是否具有父类别?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$tid = term_exists('categoryone','category',0); $term_ids = []; if ( $tid !== 0 && $tid !== null ) { $term_ids[] = $tid['term_id']; } else { // If there is not a parent category! $insert_term_id = wp_insert_term( 'categoryone','category' ); if ( ! is_wp_error ) $term_ids[] = $insert_term_id; } wp_set_post_categories( $insert_id,$term_ids );
function category_has_parent($catid){ $category = get_category($catid); if ($category->category_parent > 0){ return true; } return false; }
if(category_has_parent($tid)) { // IT has a parent }
检查孩子
function has_Children($cat_id) { $children = get_terms( 'category',array( 'parent' => $cat_id,'hide_empty' => false ) ); if ($children){ return true; } return false }
if(has_Children($tid)) { // it has children }
以上是脚本宝典为你收集整理的php – 如何检查类别是否具有父类别?全部内容,希望文章能够帮你解决php – 如何检查类别是否具有父类别?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。