Get only the top level categories using get terms wp
To get only the top level categories using get_terms in WordPress, you can use the 'parent' parameter to set it to 0. Here's an example:
$categories = get_terms( array(
'taxonomy' => 'category',
'parent' => 0,
) );
This code will retrieve all the categories that have no parent category (i.e., the top level categories) from the 'category' taxonomy. You can replace 'category' with the name of any other taxonomy you want to retrieve the top level terms from.
原文地址: https://www.cveoy.top/t/topic/cOCy 著作权归作者所有。请勿转载和采集!