Opened 3 years ago

Closed 2 years ago

#15487 closed defect (bug) (fixed)

Custom permalinks redirecting back to category list instead of post

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

Description

Using a custom permalink structure such as

/%category%/%post_id%/%postname%/

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 3 years ago.
Do not set is_(category|tag|tax) for is_singular
15487.diff (1010 bytes) - added by greuben 2 years ago.
15487-2.diff (1.8 KB) - added by greuben 2 years ago.
need some more testing

Download all attachments as: .zip

Change History (29)

  • 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   ryan3 years ago

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

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

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

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

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

  • 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

  • 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.

  • 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

I'm looking into this now.

(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

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

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

  • Resolution set to fixed
  • Status changed from reopened to closed
  • 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).

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.

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

greuben2 years ago

  • Keywords has-patch added; needs-patch removed
  • Keywords needs-patch added; has-patch removed

The last patch works but is not returning proper results

greuben2 years ago

need some more testing

  • Keywords needs-testing added; needs-patch removed
  • Keywords needs-patch added; needs-testing removed

whoops...working at wrong file and lines

Looks like scribu broke it in [16851]

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

Should be fixed now. Please confirm.

  • Keywords needs-patch removed
  • 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.