WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to get current category ID outside of the LOOP. (5 posts)

  1. palamedes
    Member
    Posted 6 years ago #

    I find myself needing to know the category ID of the currently category, outside of the loop.

    Meaning, I want to be able to simple return the cat ID, just like you can get the cat title using "single_cat_title()".

    Before I write such a device, is there one already?

    get_the_category() doesn't work correctly in this instance.

  2. palamedes
    Member
    Posted 6 years ago #

    Ah.. "get_query_var('cat');" seems to work.. Is this the correct way?

  3. palamedes
    Member
    Posted 6 years ago #

    Well since using "get_query_var('cat');" seems to work nicely I'm just going to assume its the correct way to do it..

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    It is. But only when is_category() returns true.

  5. palamedes
    Member
    Posted 6 years ago #

    Yes already doing that.. =)

Topic Closed

This topic has been closed to new replies.

About this Topic