Opened 2 years ago
Last modified 18 months ago
#17427 new defect (bug)
query_posts and tag
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Query | Version: | 3.1.2 |
| Severity: | normal | Keywords: | has-patch 2nd-opinion |
| Cc: |
Description
When i try to make a query like this:
query_posts('tag=sometag');
and "sometag" isn't previously used in some post, the query show me all the posts.
i've to add the tag in a post and after delete it ( wp just need the tag exist in "wp_terms" table) and after the query works.
Attachments (1)
Change History (10)
If that is the case, please try 3.2-beta1 as I think this has been fixed in the meantime.
SergeyBiryukov — 22 months ago
comment:3
SergeyBiryukov — 22 months ago
- Keywords has-patch added
In 3.2, querying a non-existent tag doesn't return all posts, but throws some warnings:
Notice: Trying to get property of non-object in wp-includes\general-template.php on line 1657 Notice: Trying to get property of non-object in wp-includes\general-template.php on line 1658 Notice: Trying to get property of non-object in wp-includes\post-template.php on line 465 Notice: Trying to get property of non-object in wp-includes\post-template.php on line 465 Notice: Trying to get property of non-object in wp-includes\post-template.php on line 466
17427.patch fixes the warnings.
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to 3.3
- Severity changed from major to normal
Yeah, that explains it: query flags are set even if it's a 404 in the end.
Was trying to replicate the warnings Sergey mentioned using both the current trunk and 3.2 and wasn't getting anything running query_posts on the index page - any other setup/conditions to get those notices, by chance? I'm kinda new to this, so I could be missing something.
comment:6
SergeyBiryukov — 22 months ago
In order to see those notices, WP_DEBUG should be set to true in wp-config.php.
Thanks Sergey. I did have WP_DEBUG on, but I was dropping a call to query_posts in the index.php file of the twentyeleven theme (admittedly still hacking around). After trying it in twentyten, I saw a notice like those you mentioned, so I'll go from there.
- Keywords 2nd-opinion added
I generally like the patch since these functions are known to throw errors. On the other hand, these errors are usually hit in a bad situation (like a wrong filter return value), and they're typically the only errors on the page. Seems like it's just suppressing a symptom.

So, you're saying that, instead of returning 0 posts, it returns all posts?
And then, after creating 'sometag', without attaching it to any posts, it correctly returns 0 posts?