• Resolved brandonchance

    (@brandonchance)


    I’m trying to get the children of my “Resources” category to display, but at the moment it’s only displaying the first category (leading me to believe the foreach loop isn’t working). Here’s the code:

    <?php
        $categoryslug = get_category_by_slug( 'resources' );
        $categories = wp_list_categories('title_li=0&child_of='.$categoryslug->term_id);
    
        foreach ($categories as $category) {
            echo '<h4><a>cat_ID).'">'.$category->cat_name.', </a></h4>';
        }
    ?>

    On the frontend I see “Category 1”, but I added 6 to test it.

    Any help is greatly appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Children Of Category: Foreach Loop Not Working?’ is closed to new replies.