WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 8 months ago

#17427 closed defect (bug) (duplicate)

query_posts and tag

Reported by: venerabile Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1.2
Component: Query Keywords: has-patch
Focuses: 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)

17427.patch (2.6 KB) - added by SergeyBiryukov 3 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 scribu3 years ago

  • Keywords reporter-feedback added; dev-feedback removed

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?

comment:2 scribu3 years ago

If that is the case, please try 3.2-beta1 as I think this has been fixed in the meantime.

SergeyBiryukov3 years ago

comment:3 SergeyBiryukov3 years 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.

comment:4 scribu3 years ago

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

comment:5 andyadams3 years ago

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 SergeyBiryukov3 years ago

In order to see those notices, WP_DEBUG should be set to true in wp-config.php.

comment:7 andyadams3 years ago

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.

comment:8 nacin2 years ago

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

comment:9 ryan2 years ago

  • Milestone changed from 3.3 to Future Release

comment:11 wonderboymusic8 months ago

  • Keywords 2nd-opinion removed
  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Since this ticket is 2 years old and #21394 has a more exhaustive patch that deals with every possible null instance of get_queried_object(), gonna dupe this one

Note: See TracTickets for help on using tickets.