Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 3 years ago

#4699 closed defect (bug) (fixed)

Custom Permalinks Containing Categories Are Broken for Attachments

Reported by: mtekk's profile mtekk Owned by: markjaquith's profile markjaquith
Milestone: 2.5 Priority: normal
Severity: blocker Version: 2.2.1
Component: General Keywords: attachment, permalink, category
Focuses: Cc:


Currently, with WordPress 2.2.1, when using a custom permalink structure containing the %category% tag, permalinks to attachment posts become broken. It seems to have something to do with the attachments having no category and thus cause the link to become broken.

Using the permalink scheme /archives/%category%/%postname%/ an example attachment 'bar' attached to the post 'foo' which happens to be in the general category results in the following broken permalink The permalink makes sense, but doesn't work due to the attachment post not inheriting the category(ies) of the post it is attached to.

Attachments (2)

category_permastruct_attachment.diff (1.2 KB) - added by ryan 14 years ago.
4699-rule-order.diff (934 bytes) - added by andy 14 years ago.
put explicit rules first

Download all attachments as: .zip

Change History (14)

#1 @markjaquith
15 years ago

  • Milestone set to 2.4 (future)
  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

We're forcing %postname% (post slug) to be unique anyway, so we should probably just drop %category% from the query if %postname% is present. Actually, if %postname% is present, we can probably drop all other params.

#2 follow-up: @hakre
15 years ago

what about comparing from left to right?

#3 in reply to: ↑ 2 @DD32
15 years ago

Replying to hakre:

what about comparing from left to right?

Thats not really a great fix, what if i used this as my permalink structure:


Ok its Unlikely someone would use that structure, but it shows that a left to right compare is just as useless

If we're forcing ALL post slugs to be unique, then to simplify it i'd agree that if %post_id% or %postname% is available(In that order) then it should ignore any other post-selectors in the url.

#5 @lloydbudd
14 years ago

#6299 Gallery Permalinks using /%category%/%postname%/ return 404
was closed as a duplicate of this ticket.

#6 @matt
14 years ago

  • Severity changed from normal to blocker

#7 @ryan
14 years ago

Even if you skip the category_name query whenever the request is_singular, the permalink will break because %category% gobbles up slashes and prevents the rewrite rules from recognizing the attachment. Instead of doing an attachment query, a post query is done. We'd have to change single post queries to look for both posts and attachments.

#8 @ryan
14 years ago

Creating explicit attachment links as in #6280 might help.

#9 @markjaquith
14 years ago

I like the explicit attachment links idea. Also prevents the "feed.jpg" issue, if we weren't already dealing with that.

#10 @ryan
14 years ago

That patch gets us part of the way there, but the attachment rewrite rules aren't ordered early enough to prevent the category regex from claiming attachment as part of the category name.

14 years ago

put explicit rules first

#10 @ryan
14 years ago

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

(In [7531]) Fix attachment links for permalink structures containing category tag. Props andy. fixes #4699

#11 @hakre
13 years ago

regression test against 2.8 trunk successfully passed.

This ticket was mentioned in Slack in #core-site-health by afragen. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.