Support » Fixing WordPress » the_category_ID does not work..

  • Resolved Anonymous

    <?php echo the_category_ID() ?> does not work on my blog… It always comes out as zero. Regardless if I have the “echo” in there or not, it always comes out as 0 … I was using it for category images. But on all the old posts I made that had been converted from b2, it works… >_< Help here?

Viewing 7 replies - 1 through 7 (of 7 total)
  • This is a known problem. Check the WPBug page on the wiki, Some people have came up with a workaround, but this function is no longer working, and rumor has it, no longer supported.

    That link does not reveal much :-). I would appreciate more info on this subject too – presumably there is a way of retreiving category (‘s) for each post.

    The link ended up with a period in it and should be – Look down the page for 1.2 frequent problems & bugs. This is one of them.
    Previous forum entries on this at
    And if you search on the function name, I think you’ll find other threads.
    Supposedly there might be a 1.2.1 branch, and this might be fixed in it. And a suggestion has been made to use get_the_category instead.

    I came up with a short workaround for this bug bear in mind I don’t understand the whole wordpress system so if my code is sloppy don’t get on my case. just put the following code in your template-functions file:
    function this_cat_id($seperator = ”) {
    $categories = get_the_category();
    $i = 0;
    foreach ($categories as $category) {
    $category->cat_name = stripslashes($category->cat_name);
    if (0 < $i) echo $seperator . ‘ ‘;
    $output = $category->category_id;

    I’ve looked at that code provided above and I’d say it’s doing too much work… my solution is:

    (insert at end of wp-includes/template-functions-category.php)
    function print_cat_id()
    $categories = get_the_category();
    foreach ($categories as $category)
    echo $category->category_id;

    This prints the first category (as stored in the WP database). I figure if you want it to print a list of category IDs it’s a different question, but this is what works as a replacement for the_category_id imho
    — Karan

    dunno why that took so long for someone to post.

    <?= $_GET['cat']?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘the_category_ID does not work..’ is closed to new replies.