#27213 closed defect (bug) (invalid)
in_category() returns true in Home page on local install
Reported by: | Marventus | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
Hello, guys. I've been scratching my head on this one for a few hours.
If you run the attached script on a live site, nothing gets echoed on the home page of a live WP installation. However, if you run it locally, the opposite occurs.
I'm running WP locally on XAMPP 1.7.7 with the following config:
+ Apache 2.2.21
+ MySQL 5.5.16 (Community Server)
+ PHP 5.3.8 (VC9 X86 32bit thread safe) + PEAR
+ XAMPP Control Panel Version 2.5 from www.nat32.com
+ (BETA) XAMPP Control Panel Version 3.0.2 by Steffen Strueber (not in the USB & lite version)
+ XAMPP Security
+ OpenSSL 1.0.0e
+ phpMyAdmin 3.4.5
Attachments (1)
Change History (6)
#1
follow-up:
↓ 2
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
I think this belongs on the support forums: https://wordpress.org/support/
That said, I suspect your posts are not the same between environments - in_category()
applies to a specific post, and shouldn't be used in wp_head
without checking if you're looking at a singular item or else you might get unpredictable results.
#2
in reply to:
↑ 1
;
follow-up:
↓ 5
@
11 years ago
Replying to helen:
Hi, Helen. Thanks for pitching in.
That said, I suspect your posts are not the same between environments
Nope, they are actually. Dbs are the same (local is a dump from live with different site and home urls)
in_category()
applies to a specific post, and shouldn't be used inwp_head
without checking if you're looking at a singular item or else you might get unpredictable results.
I agree with you. I stumbled upon this by accident while trying something else, and wrote that little plugin for testing purposes only.
However, the function should return the same output regardless of the environment WP is running on, right?
#4
@
11 years ago
Don't worry about it: it's one in a million. Let's leave it closed for now and if I have more info I'll post it here.
Thanks for your help!
#5
in reply to:
↑ 2
@
11 years ago
Replying to Marventus:
Replying to helen:
That said, I suspect your posts are not the same between environments
Nope, they are actually. Dbs are the same (local is a dump from live with different site and home urls)
You can modify your function to confirm that:
function tgitest_in_category() { echo '<pre>'; print_r( get_post() ); echo '</pre>'; if ( in_category( 'reviews' ) ) echo 'This is a test for admins only. Please disregard.'; } add_action( 'wp_head', 'tgitest_in_category' );
Short Testing plugin