Opened 11 years ago
Last modified 3 years ago
#27266 new defect (bug)
Front end search for attachment title cannot succeed
Reported by: | dglingren | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.9 |
Component: | Query | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description (last modified by )
This is somewhat related to ticket #22556 but affects all queries that use the keyword search parameter, 's'.
Typing an attachment's title into the "front end" search box generated this query:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '%Guatemala%') OR (wp_posts.post_content LIKE '%Guatemala%')) AND ((wp_posts.post_title LIKE '%IRF3%') OR (wp_posts.post_content LIKE '%IRF3%'))) AND wp_posts.post_type IN ('post', 'page', 'attachment') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') ORDER BY (CASE WHEN wp_posts.post_title LIKE '%Guatemala IRF3%' THEN 1 WHEN wp_posts.post_title LIKE '%Guatemala%' AND wp_posts.post_title LIKE '%IRF3%' THEN 2 WHEN wp_posts.post_title LIKE '%Guatemala%' OR wp_posts.post_title LIKE '%IRF3%' THEN 3 WHEN wp_posts.post_content LIKE '%Guatemala IRF3%' THEN 4 ELSE 5 END), wp_posts.post_date DESC LIMIT 0, 2
Although the post_type
clause includes attachment
, the post_status
test always fails because attachments have a post_status
of inherit
.
Attachments (1)
Change History (18)
#2
@
11 years ago
- Description modified (diff)
- Keywords close removed
helen: I think, dglingren doesn't want to search for attachments, he's just saying that
AND wp_posts.post_type IN ('post', 'page', 'attachment')
is contradicting with
AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private')
because attachment
s always have a post_status
of inherit
.
The front end search does indeed result in this SQL query. I could not yet check if attachment
s can have other post_status
values.
The list of post types comes from get_post_types( array('exclude_from_search' => false) )
.
#3
@
11 years ago
@TobiasBg interpreted my issue correctly; the two clauses contradict each other and I do not know whether the original intent was to include "Media Pages" in the search results or not. I am reporting this on behalf of one of my plugin users who does not understand why the front end search can't find any of the single attachment pages for his Media Library items, even when he puts the attachment title in the search box.
#6
in reply to:
↑ 5
@
11 years ago
Replying to dglingren:
Did you really mean 2.9, or perhaps 3.9?
Version is used to indicate when it was first introduced. This has been around since post types were introduced (I think).
#7
@
10 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
This seems like a valid concern. A patch could move this along nicely.
#10
@
9 years ago
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
Since attachments now have pretty permalinks all the time (even without being actually attached to a post), it may make more sense to check for the 'inherit'
post status here.
It would be quite a simple change, though people might wonder why their attachments are suddenly discoverable via search.
See 27266.diff
If you want your site search to include attachments, you'll need to alter the query via
pre_get_posts
or similar to include the inherit status. I'm not sure we should be changing this now, as it would cause behavior to change on people's sites whether they want it or not.