WordPress.org

Ready to get started?Download WordPress

Forums

in_category bug? (8 posts)

  1. eykd
    Member
    Posted 9 years ago #

    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.)

  2. eykd
    Member
    Posted 9 years ago #

    Hmph. Silly me. Just remove the && !$single from the If clause in Matt's example. Nevermind.

  3. TechGnome
    Moderator
    Posted 9 years ago #

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

  4. Beel
    Member
    Posted 9 years ago #

    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?

  5. TechGnome
    Moderator
    Posted 9 years ago #

    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

  6. Beel
    Member
    Posted 9 years ago #

    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...

  7. TechGnome
    Moderator
    Posted 9 years ago #

    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

  8. fitz
    Member
    Posted 8 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.