Ready to get started?Download WordPress


[resolved] Get multiple category names inside the loop (3 posts)

  1. applegateian
    Posted 1 year ago #

    I need to be able to get all the category names within a post in the loop.

    I have checked out WordPress get_the_category on this, and the example Show the First Category Name Only
    works how I want, but only shows One category:

    $category = get_the_category();
    echo $category[0]->cat_name;

    How do I get all of them?



  2. Your answer was right there in the Codex: Function Reference/get the category page under the "Show All Categories as Links" section :)

    Slightly modified/simplified:

    $categories = get_the_category();
    if( $categories ) {
        foreach( $categories as $category ) {
            echo "$category->name<br />";
  3. applegateian
    Posted 1 year ago #

    Worked perfectly, thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic