• Hi,

    I need to be able to pull the current category’s ID, and that ID only.

    I’ve tried the following piece of code
    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_ID . ' '; } ?>

    Whilst that does pull the current categories ID, it also appears to be pulling the last sub-category for the category’s ID.

    For example, Category 11 has a sub-category, Category 12.
    So when I’m on category 11s page, the above query spits out the following: 11%2012.

    I need it to only spit out 11 when I’m on parent category 11s page, and only spit out 12 when I’m on sub-category 12s page.

    Any ideas anyone?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Well, then don’t loop thru the cat IDs, just spit out the first one.

    Thread Starter mylagoon

    (@mylagoon)

    The first one it spits out is the incorrect Cat ID when you are on a sub-category page.

    $current_page_cat = $wp_query->get_query_var('cat');

    Thread Starter mylagoon

    (@mylagoon)

    I’ve entered the above as follows:
    <?php $current_page_cat = $wp_query->get_query_var('cat'); ?>
    But all it seems to do is stop the rest of the coding for the page below it from loading.

    I’ve probably done something really simple wrong yeah?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pull current category ID information’ is closed to new replies.