Support » Fixing WordPress » in_category bug?

  • Using WP 1.2–
    in_category only seems to work when you’re displaying more than one post. When you address a single post (i.e. index.php?p=x) , in_category seems to always return False.
    Example:
    I have two different categories of posts, poems and prose. I want poems to be formatted as, well, poems, and prose to be formatted normally, and I’d like categories to do the work (i.e. inserting special divs) so I don’t have to. So, I use Matt’s aside trick with in_category and If…Else code, with butter and salt. Except, when I display the poem by itself, via the permalink, it’s jumped the If and formatted the text as a prose post. Bug, or feature? And how might I work around it?
    (Note that you get this behavior with Matt’s asides… just it’s more natural.)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hmph. Silly me. Just remove the && !$single from the If clause in Matt’s example. Nevermind.

    At least you got it to work. Mine seems to return nothing…… ????
    TG

    Darn, I think it was this thread I was hoping to see more on. I have in_category() working on my front page but was trying to use it with is_archive() to display a different format for an archive of a particular category. I’ll have to think a bit harder.
    TG: what have you got and what are you trying to do?

    Follow the bouncing pixels….
    The catID I’m looking for is -1, but no matter what ID I pass it doesn’t return….. no errors either…..
    It *shouldn’t* be this hard.
    TG

    in_category only checks the post category and returns true or false. I think I saw something about what you are trying to do in another post. I will go look for it in a minute…

    That’s all I want it to do…. I want to know if the current post being displayed (be it on the main page – in a WPLoop – or single – because the post itself is being displayed) is in the this hidden category. Based on what I’m reading the other thread, I think I’m going to need to work this from scratch.
    TG

    i’m using wp 2.0.4 and have actually the same problem, that this function ( in_cetegory() ) does not work at all. it always returns false. i looked a bit into it and found out, that the global variable “$category_cache” is in any case of request null. so i’m adding the function call “update_post_category_cache( $post->ID );” in front of any in_category use. this solved my problem.
    But i’m not sure, if this is a bug or not, nor if this is the right way of solving the problem. any information on this would be great.

    [beep] :: fitz

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘in_category bug?’ is closed to new replies.