Support » Fixing WordPress » Getting the post’s catID

  • TechGnome

    (@techgnome)


    Moderator

    According to the Wiki documentation the_category_ID() will return the category id the post is in.

    The ID (number) of the category the post belongs to.

    How ever, it seems to always return 0, no matter what I do. I wanted to use it to check to see if the post is in one particular category (it will be the only category the post(s) will be in, so multi-cats aren’t an issue – I think) and if so, I want to change how some of the post meta info is displayed.
    So what’s the deal? Does it not work, or is it left over legacy code from the single cat days?
    Does anyone have any ideas on how to check the cat id of a post? If there are more than one, I know immediately that it isn’t in the special category, so that helps some, but I’d say that 80% of my posts are single cat posts, so that’s only going to work once in a while.
    Any clue?
    TG

Viewing 15 replies - 1 through 15 (of 16 total)
  • try in_category();
    example is here:
    http://photomatt.net/archives/2004/05/19/asides/

    TechGnome

    (@techgnome)


    Moderator


    You know, I saw that earlier and it just didn’t click ….. now it does… Thanks, I’m going to give it a go.
    *fingers = crossed*
    TG

    TechGnome

    (@techgnome)


    Moderator


    well, that didn’t seem to work. The function doesn’t appear to return anything.
    TG

    how are you using it?

    TechGnome

    (@techgnome)


    Moderator


    Like so:

    <?php if (in_category(-1)) { ?>
    ... hide the meta info for the post ...
    <?php } else { ?>
    ... show post meta info ...
    <?php } ?>
    OK, now, I have to admit that there is no such catID as -1 in my database, I'm using it as a pseudo hidden category, I've got a plugin that sets it to -1 based on a setting.
    The catID is in fact -1 -- I checked the database itself ala phpMyAdmin just to make sure.
    But even when I put in 1 or 3 or 7 in the function call, just to see, I got nothing.
    TG

    are you using the function within the Loop?

    TechGnome

    (@techgnome)


    Moderator


    Yes I am…..
    Inside the loop, where the post meta info is procedded – “Filed Under: X, Y, Z By: Author at 12:43PM, etc…” That’s the stuff I’m trying to deal with. When I’m displaying a post of Catid = -1, I want to not display the meta info, but if it’s a normal post, then I do want the meta. Is this making any sense?
    TG

    are you using 1.2?

    TechGnome

    (@techgnome)


    Moderator


    1.2 Mingus….. I even found the function in the wp-includes/templates-functions-post.php file.
    TG

    i have no clue what the problem could be.

    try something simpler without the if statement and the -1. maybe just echo the function.

    the_category_ID hasn’t worked for a while now:
    http://mosquito.wordpress.org/bug_view_page.php?bug_id=0000096
    The guys on this thread sound like they might be trying to do something similar to you but don’t know if they ever got a solution 🙁

    TechGnome

    (@techgnome)


    Moderator


    charle97 – that was the first thing I tried – nada.
    Anon – what the—….. how in the world is Matt using the damned thing then? grumble, grumble…….
    *kicks a stone off the cliff*
    TG
    GAH! I jsut checked the bug you linked to…. it’s friggin depreciated… no wonder it doesn’t work. For crying out loud. Puts me bac kat square one.

    TechGnome

    (@techgnome)


    Moderator


    Hey all, I appreciate the help, but I’ve given up. Nothing works. I was hoping to do this w/o having to modify any core files. Since none of it works, I’m not going to be able to do what I want. I thought about using the_category and chec kt osee if anything is passed back, but it echoes hte results instead of returning it.
    *sigh*
    Damn shame. Had such high hopes.
    Adios.
    TG

    try this:
    http://wordpress.org/support/3/4801#post-28758
    i used that before matt coded in_category.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Getting the post’s catID’ is closed to new replies.