[wp-trac] [WordPress Trac] #50873: Search query parameter causes 404 on pagename match rules

WordPress Trac noreply at wordpress.org
Fri Aug 7 14:55:32 UTC 2020


#50873: Search query parameter causes 404 on pagename match rules
--------------------------+-----------------------------
 Reporter:  MikeNGarrett  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  5.4.2
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 With permalinks turned on, visit a post or page. Then append `?s=test` to
 the url. It should look like this: `https://example.com/post-
 slug/?s=test`. You will probably hit the 404 page.

 The expected behavior is to get to the post or page you hit, ie
 `https://example.com/post-slug/`

 Instead, you hit a 404 page.

 This is due to both the search query and post slug query getting combined
 instead of one taking priority over the other.

 The resulting query is a combination of a search query and post slug query
 which results in no posts being found, unless the search term is also in
 the post slug. See below:
 {{{
 SELECT wp_posts.*
 FROM wp_posts
 WHERE 1=1
 AND wp_posts.post_name = 'post-slug'
 AND (((wp_posts.post_title LIKE '%test%')
 OR (wp_posts.post_excerpt LIKE '%test%')
 OR (wp_posts.post_content LIKE '%test%')))
 AND wp_posts.post_type = 'post'
 ORDER BY wp_posts.post_title LIKE '%test%' DESC, wp_posts.post_date DESC
 }}}
 This is using `https://example.com/post-slug/?s=test` as the example url.

 I would expect the search query string to be ignore unless the visitor is
 on the search page (front/home page by default).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50873>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list