WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#16438 closed defect (bug) (duplicate)

page and attachment conflict

Reported by: ejikas Owned by:
Milestone: Priority: normal
Severity: critical Version: 3.0.4
Component: Query Keywords: has-patch
Focuses: Cc:

Description

this bug noticed on 3.0.4 and also in the 3.1-RC3-17376. Also I noticed it was written about it 4months ago in support forum: http://wordpress.org/support/topic/attachment-post-slug-not-being-checked-for-duplicates

In short: instead of the page getting attachment page.

How to see the bug:

  1. using permalinks.
  2. upload an image to the media gallery.
  3. created Page with the same slug like was the file name.

if the file name was 1-200x150.jpg so page slug should be 1-200x150,
if the file name was about-group.jpg so the new page slug should be about-group.

  1. publish the page and try to view it. Instead of the page you will get the attachment page.

if you would insert the image to any post/page the bug would dissapear. even after you remove the image from the page content (it remains in the page gallery)


the bug is there:
file: wp-includes/query.php,
line #1509: $this->queried_object =& get_page_by_path($qvpagename?);

or in other words the function get_page_by_path(), that is in wp-includes/post.php, line #2890.

it's easy to see if both page and attachment share one slug and the attachment has no "parent" it leads to the bug.


suggestion/question:


not sure why the it is used function get_page_by_path() that queries not only pages but attachments too. I think there should be called function like get_page_by_slug (or ..by_name) that queries only page type records. If I'm not mistaken for attachments and attachment pages wp generates different rewrite rules with no var "pagename". If I'm right should be changed the call in query.php

Attachments (1)

16438.diff (743 bytes) - added by jltallon 4 years ago.
Remove post_type='attachment' from get_page_path

Download all attachments as: .zip

Change History (6)

comment:1 @ejikas4 years ago

  • Keywords page attachment slug added

@jltallon4 years ago

Remove post_type='attachment' from get_page_path

comment:2 @scribu4 years ago

  • Keywords has-patch added; page attachment slug removed

comment:3 @Ipstenu4 years ago

You can also do this if you have a 'sub page'

Make a page: foobar - URL is example.com/foobar/

Upload an image to that page: baznarf.jpg - URL is example.com/foobar/baznarf

Make a page under foobar called baznarf - URL is example.com/foobar/baznarf

Whoops.

comment:5 @SergeyBiryukov4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.