version_compare(get_bloginfo('version'),'4.5', '>=')
Ví dụ: Kiểm tra phiên bản wp của bạn để thực hiện hàm lấy tất cả các term theo taxonomy trong WordPress
function tm_get_all_cats_post( $taxonomy ){
$list_terms = array();
if(version_compare(get_bloginfo('version'),'4.5', '>=') ){
$list_terms = get_terms( array(
'taxonomy' => $taxonomy,
'orderby' => 'parent',
'hide_empty' => false,
) );
}else{
$list_terms = get_terms( $taxonomy, array(
'orderby' => 'parent',
'hide_empty' => false,
) );
}
$new_cats = array();
foreach ( $list_terms as $key => $term ) {
if( $term->parent != 0 ){
$existent_term = get_term( $term->parent, $taxonomy );
$term->parent = $existent_term->slug;
}
$new_cats[$key] = $term;
}
return $new_cats;
}