Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#16786 closed defect (bug) (worksforme)

Setting permalinks programatically breaks custom post type URL's

Reported by: gilbitron Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: Rewrite Rules Keywords: 2nd-opinion reporter-feedback
Focuses: Cc:


Using a function to programatically set permalinks (see attached) breaks custom post type URL's. A 404 page is displayed instead.

Visiting the Permalinks settings page fixes the issue (you don't even need to save the permalinks settings).

It turns out that you need to call $wp_rewrite->flush_rules() on the following page load for it to work, even though this is called at the end of the modify_permalinks() function.

Possibly related to #16736

Attachments (1)

modify_permalinks.php (2.2 KB) - added by gilbitron 11 years ago.

Download all attachments as: .zip

Change History (4)

#1 @scribu
11 years ago

  • Keywords reporter-feedback added

It's important when you're calling modify_permalinks() as well.

#2 @nerx
11 years ago

Just to mention: $permalink_structure will collapse if you use it to modify!

#3 @nacin
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I could see this being an issue if the post type isn't registered before modify_permalinks() is called. So, wait until wp_loaded.

Note: See TracTickets for help on using tickets.