WordPress supports Categories. A Post can be assigned to single or multiple categories in WordPress. Also categories can be single level or multi level (nested). To get only parent categories and exclude the child categories the following code can be used.
<?php
$args = array(
'orderby' => 'name',
'parent' => 0
);
$categories = get_categories($args);
?>
$categories contains all the parent level categories only.
No comments:
Post a Comment