[wp-trac] [WordPress Trac] #14846: in_category returning true when last post is from specified category

WordPress Trac wp-trac at lists.automattic.com
Sat Sep 11 15:42:51 UTC 2010


#14846: in_category returning true when last post is from specified category
-----------------------------+----------------------------------------------
 Reporter:  enrique-ramirez  |       Owner:                 
     Type:  defect (bug)     |      Status:  new            
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  General          |     Version:  3.0.1          
 Severity:  major            |    Keywords:                 
-----------------------------+----------------------------------------------
 I'll try to be as clear as possible with this. I've added a single line to
 my index.php file for testing purposes, right before I start my loop:


 {{{
 <?php if ( in_category('8') ) { ?>Category 8<?php } else { ?>Blog<?php }
 ?>

 <?php query_posts('&cat=-8'); ?>
 ... loop here...
 }}}

 Please note I do NOT display posts in category 8 in my index.php file.
 Posts with category 8 are displayed in another page, hidden from the main
 index.

 Everything works as expected. When I go to index.php I can see my blog
 index and the word "Blog" being printed out, and posts from category 8 are
 not displayed.

 Problem is when, on my WP Admin panel, the LATEST post is from category 8.
 Even when it does not appear on the index page, the word "Category 8" is
 printed instead of blog.

 Once again, this is the post index page. I'm NOT in the single.php
 template, nor in a category specific page (so is_category() is out of the
 question).

 '''So, in resume:''' If the latest post added is from category 8,
 index.php assumes it is IN category 8, even though it's the post index
 (not a Category specific page, nor a single post page) AND despite the
 post NOT even being displayed; the in_category condition is not even
 inside the loop.

 Quite an issue since I'm using in_category for different sidebars, which
 are being completely ruined by this one issue.

 Note:
 Issue is fixed if the LATEST post is viewable by the user. For example, if
 I add a private post after the latest "Category 8" post and am logged in,
 in_category returns false. If, on the contrary, I check index.php logged
 out, in_category returns false (even though the latest post is outside
 category 8, I don't have permission to view it and in_category returns
 false).

 Another note: it doesn't matter if the post index displays the posts or
 not. If I have permission to access the latest post, in_category will
 return true if the latest one is from category 8 and false if it's
 somewhere else.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14846>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list