WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get Category ID for the archive page being viewed (3 posts)

  1. jamesk5a
    Member
    Posted 5 years ago #

    I'm trying to work out how to get the category ID for the archive/category that's currently being viewed.

    In otherwords, when I'm viewing domain.com/archive/category/<CategoryName>/ I want to get the ID for the corresponding 'Category name' -- without having to query something within the loop.

    I think a few people have asked this before, but either haven't got a response, or asked this question but meant to ask something else.

  2. MichaelH
    Member
    Posted 5 years ago #

    This?

    <?php
    $category = $wp_query->get_queried_object();
    echo 'cat name  ' . $category->name;
    echo 'cat id  ' . $category->cat_ID;
    ?>
  3. jamesk5a
    Member
    Posted 5 years ago #

    Yep, that's exactly what I needed (well, apart from the fact that I needed to put the cat_Id into a $var). Thanks! :D

Topic Closed

This topic has been closed to new replies.

About this Topic