WP_Term_Query 只取第一層分類
只取得第一層分類,初始化參數中parent為0即可
$args = array( 'taxonomy' => 'category', 'orderby' => 'name', 'order' => 'ASC', 'parent' => 0, 'hide_empty' => false, ); $the_query = new WP_Term_Query($args); $categories = $the_query->get_terms(); print_r($the_query); exit;
Thanks, great article.
You’re welcome