Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#15487 closed defect (bug) (fixed)

Custom permalinks redirecting back to category list instead of post

Reported by: tott Owned by: garyc40
Milestone: 3.1 Priority: high
Severity: blocker Version: 3.1
Component: Canonical Keywords:
Focuses: Cc:


Using a custom permalink structure such as


hitting a post permalink will redirect you back to the category although debugging via a filter attached to parse_request shows the correct query (matched_query).

Attachments (3)

15487.singular.diff (882 bytes) - added by markjaquith 5 years ago.
Do not set is_(category|tag|tax) for is_singular
15487.diff (1010 bytes) - added by greuben 5 years ago.
15487-2.diff (1.8 KB) - added by greuben 5 years ago.
need some more testing

Download all attachments as: .zip

Change History (29)

comment:1 @nacin5 years ago

  • Component changed from Rewrite Rules to Canonical
  • Keywords needs-patch added; permalink_structure wp_rewrite rewrite removed
  • Milestone changed from Awaiting Review to 3.1

comment:3 @ryan5 years ago

canonical.php is confused. I think it sees this as a tax query rather than a single post query.

comment:4 @mtekk5 years ago

It is broken for all instances of %category% in your permalinks e.g. /archives/%category%/%postname% is broken as well

comment:5 @mtekk5 years ago

The latest revision that it works on is [16379], it is broken by the next revision [16380]

comment:6 @markjaquith5 years ago

is_category is being set, and it shouldn't be.

@markjaquith5 years ago

Do not set is_(category|tag|tax) for is_singular

comment:7 @markjaquith5 years ago

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

(In [16495]) Do not set is_category/is_tax/is_tax for is_singular requests. props mtekk. fixes #15487

comment:8 @mtekk5 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Still broken, and is sort of worse now. Can end up in infinite redirect loops, or lead to pages instead of posts. Must be more to this, unless I have borked my testbed install somehow.

From what I can tell, if there is only one post in the category WordPress is able to find the correct page 100% of the time. If there are multiple posts in the category, it seems like the most recent post is the only one that will load reliably. This is true for all categories except the default category (Uncategorized or as I have it renamed General). The default category is broken, all of the posts that are members of it end up getting stuck in redirect loops.

comment:9 @markjaquith5 years ago

  • Priority changed from normal to high
  • Severity changed from normal to blocker

My fault... had some code in mu-plugins that was messing with redirects. I see the problem exhibited fully, now. Bumping up priority/severity. Can take a look tonight, but if someone wants to take a swing in the meantime, go ahead.

is_category should be FALSE for these requests, because they're is_single requests. And the category portion of the URL is typically ignored when making the query (because you have a unique post slug or ID) — that may have changed in 3.1

comment:10 @scribu5 years ago

I'm looking into this now.

comment:11 @ryan5 years ago

(In [16513]) array_unique() categoryin and categorynot_in to eliminate dupes from multiple runs of parse_tax_query(). Fixes canonical redirects for cat, categoryin, and categorynot_in requests. see #12891 #15487

comment:12 @automattor5 years ago

(In [16515]) Don't do any taxonomy stuff if is_singular. See #15487

comment:13 @mtekk5 years ago

Looks like the last commit by automattor fixed it. Anyone else confirm?

comment:14 @ryan5 years ago

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

comment:15 @tar.gz5 years ago

  • Cc tar.gz added
  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm currently running 3.1-beta1-16732 and I see this issue reappearing on a site that was fine in WP 3.0.3.

My custom link structure is: /%year%/%category%/%postname%/ (since starting with %category% is not recommended for performance reasons).

comment:16 @tar.gz5 years ago

Note: the previous beta build i was running was [16723], here the permalinks were still working.

Note2: a custom structure such as /%year%/%postname%/ works fine, so it's really the %category% that causes the trouble.

comment:17 @garyc405 years ago

  • Owner set to garyc40
  • Status changed from reopened to assigned

@greuben5 years ago

comment:18 @greuben5 years ago

  • Keywords has-patch added; needs-patch removed

comment:19 @greuben5 years ago

  • Keywords needs-patch added; has-patch removed

The last patch works but is not returning proper results

@greuben5 years ago

need some more testing

comment:20 @greuben5 years ago

  • Keywords needs-testing added; needs-patch removed

comment:21 @greuben5 years ago

  • Keywords needs-patch added; needs-testing removed

whoops...working at wrong file and lines

comment:22 @mtekk5 years ago

Looks like scribu broke it in [16851]

comment:23 @scribu5 years ago

(In [16880]) Don't set query flags in parse_tax_query(). See #15487

comment:24 @scribu5 years ago

Should be fixed now. Please confirm.

comment:25 @scribu5 years ago

  • Keywords needs-patch removed

comment:26 @mtekk5 years ago

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

Ok, works for me now, again, closing as fixed

Note: See TracTickets for help on using tickets.