WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16626 closed defect (bug) (fixed)

CPT archive rewrite rule doesn't respect 'with_front' arg

Reported by: scribu Owned by: scribu
Milestone: 3.1.1 Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description (last modified by scribu)

  1. Have WP MS activated, with subdirectories, not subdomains.
  1. Register a custom post type, with has_archive => true.
  1. On the main blog, call get_post_archive_link().

The URL will include the /blog/ prefix, but it will lead to a 404, since the rewrite rule isn't correct.

Attachments (2)

16626.diff (796 bytes) - added by scribu 3 years ago.
test-16626.php (389 bytes) - added by scribu 3 years ago.
Clearer

Download all attachments as: .zip

Change History (14)

comment:1 scribu3 years ago

  • Description modified (diff)
  • Summary changed from get_post_archive_link() includes /blog/, when it shouldn't to CPT archive rewrite rule doesn't respect 'with_front' arg

scribu3 years ago

comment:2 scribu3 years ago

  • Keywords has-patch added

The trouble comes from the fact that $wp_rewrite->add_rule() is used directly, which doesn't have a $with_front argument.

See 16626.diff.

Last edited 3 years ago by scribu (previous) (diff)

comment:3 rfair4043 years ago

Seems that 16626 does work. When I previously rec'd a 404 not found error when trying to load a single custom post type. When I used your diff, I am now able to see the post. still uses the /blog url structure, which is another issue though.

Version 0, edited 3 years ago by rfair404 (next)

comment:4 scribu3 years ago

still uses the /blog url structure, which is another issue though.

Yes, that's the idea. If you don't want to use /blog, just say so:

register_post_type( ..., array(
  'rewrite' => array( 'with_front' => false ),
  ...
) );
Last edited 3 years ago by scribu (previous) (diff)

comment:5 rfair4043 years ago

seems that using 16626.diff caused this error though.

Fatal error: Cannot redeclare class Walker_Page in /.../wp-includes/post-template.php on line 1062

comment:6 scribu3 years ago

Are you sure that's not caused by a plugin or theme?

comment:7 nacin3 years ago

Walker_Page was moved from wp-includes/classes.php (and that file was killed) to wp-includes/post-template.php. I would make sure your upgrade was complete.

scribu3 years ago

Clearer

comment:8 scribu3 years ago

  • Owner set to scribu
  • Status changed from new to reviewing

Follow-up: #16725

comment:9 scribu3 years ago

  • Keywords commit added

comment:10 azizur3 years ago

  • Cc azizur added

comment:11 markjaquith3 years ago

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

(In [17514]) Use with_front properly when creating rules for CPT archive pages. props scribu. fixes #16626 for trunk

comment:12 markjaquith3 years ago

(In [17515]) Use with_front properly when creating rules for CPT archive pages. props scribu. fixes #16626 for 3.1

Note: See TracTickets for help on using tickets.