How To Loop Through Post Categories In WordPress

Trying to loop through post categories? All you may need is to use the get_categories() function to loop through them with a PHP foreach loop.

Looping through WordPress post categories

To loop through WordPress post categories, copy and paste the code below into the file you wish to display them on.

foreach ( get_categories() as $category ) :
     echo $category->name;

get_categories() not working?

As per this guide, you need to pass hide_empty into get_categories() in order to display all unused categories too.