WordPress.org

Support

Support » Themes and Templates » [Resolved] Get Category ID for the archive page being viewed

[Resolved] Get Category ID for the archive page being viewed

  • jamesk5a

    @jamesk5a

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    @michaelh

    This?

    <?php
    $category = $wp_query->get_queried_object();
    echo 'cat name  ' . $category->name;
    echo 'cat id  ' . $category->cat_ID;
    ?>

    jamesk5a

    @jamesk5a

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Get Category ID for the archive page being viewed’ is closed to new replies.
Skip to toolbar