Saturday, May 21, 2016

WordPress get parent categories

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

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...