Make WordPress Core

Opened 13 years ago

Closed 11 years ago

Last modified 10 years ago

#19198 closed defect (bug) (fixed)

Die fast in get_posts if in_search_post_types returns nothing

Reported by: mitchoyoshitaka's profile mitchoyoshitaka Owned by: ryan's profile ryan
Milestone: 3.7 Priority: normal
Severity: minor Version: 3.2.1
Component: Query Keywords: has-patch
Focuses: Cc:


From a comment of mine in #18364, which nacin suggested was worth a follow-up ticket:

Just noticed that this logic here might in fact have a flaw: if there are no post types which have exclude_from_search = false, then magically *all* post types will be checked? Am I reading this right? In that case, shouldn't we just immediately return no results?

Obviously, this wouldn't be an issue except in a very customized setup where all post types have exclude_from_search = true, but still... thoughts anyone?

Attachments (4)

19198.diff (889 bytes) - added by mitchoyoshitaka 13 years ago.
19198.2.diff (708 bytes) - added by mitchoyoshitaka 13 years ago.
19198.3.diff (675 bytes) - added by wonderboymusic 11 years ago.
19198.4.diff (1.6 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (10)

#1 @mitchoyoshitaka
13 years ago

  • Owner set to ryan
  • Status changed from new to reviewing

This patch incorporates two decisions:

  1. Whether to just kill the query immediately or to continue building the (no-row-returning) query. I believe we *should* continue to build the SQL query and let it run as some filter might come along and save the query, making it non-trivial.
  2. How to create a . My first intuition was to always add null to the list of post_types in (), but then trivial cases such as post_types in (null, 'post') has the potential of being (probably only a little) slower than post_types in ('post'). The solution presented here just makes it post_types in (null) in cases when $in_search_post_types is empty.

Feedback welcome.

#2 @nacin
13 years ago

1=0 is generally how we kill a query.

#3 @coffee2code
12 years ago

  • Version set to 3.2.1

#4 @wonderboymusic
11 years ago

  • Milestone changed from Awaiting Review to 3.7

Refreshed patch against trunk as it was blowing up - this one makes sense, moving to 3.7

#5 @wonderboymusic
11 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 25239:

Kill the query in the following edge case: post_type => 'any' but exclude_from_search => false returns no valid post types. Adds unit tests.

Props mitchoyoshitaka.
Fixes #19198.

#6 @SergeyBiryukov
10 years ago

In 28800:

Add @ticket references.

see #16854, #19198.

Note: See TracTickets for help on using tickets.