Next Previous

WP Get Categories

Get All Categories

To get all the categories, including subcategories data without any HTML, call get_categories() function with no arguments.

This will return an array of Category objects.

Loop through an array and print individual category name and ID.

foreach (get_categories() as $cat) {
    echo '<div style="border:1px solid blue">';
    echo 'category name = ' . $cat->name . '<br>';
    echo 'category ID = '. $cat->cat_ID . '<br>';
    echo '</div>';

And the output would look like this:

Display All Categories

If you want to get all categories with preformatted HTML, call wp_list_categories() function.

This function organizes categories and subcategories in an unordered lists format.

Next Previous

Join Over 1000 🔥

Hey, Like What You're Reading?

JOIN to learn more about WordPress

Valid 9th - 14th Jul 2020
85% OFF

Vue.js & Google Maps API: Build Location-Based Web Apps Like A Pro!

🔥 1086+ students enrolled!
4.85 ⭐️⭐️⭐️⭐️⭐️ (31+ ratings)