Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#13712 closed defect (bug) (worksforme)

When Pretty Permalinks Enabled Custom Post Types 404 Not Found

Reported by: jackreichert's profile jackreichert Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Permalinks Keywords:
Focuses: Cc:

Description

Running the WP 3.0 RC1 on a MAMP server - latest updates of both.

When any of the pretty-permalinks are enabled either pages or the custom post types come up as 404 not found, whether while trying to access the custom post via the "view" link in the backend or trying manually by typing in the url.

The custom post type was created using the Custome Post Type UI plugin and code pasted into the functions.php in the theme.

Change History (14)

#1 @ocean90
16 years ago

After creating the custom post type, do you refreshed the permalinks? (Refresh = Visit settings -> permalinks page and save again)

#2 @jackreichert
16 years ago

Yup. First thing I thought to do. When I do, pages work. But custom post types still do not until I revert to the default.

#3 @ocean90
16 years ago

Can you paste your code?

#4 @jackreichert
16 years ago

Sure

<?php Custom Post Types

register_post_type('newsletters', array( 'label' => 'Newsletters','public' => true,'show_ui' => true,'capability_type' => 'post','hierarchical' => true,'can_export' => true,'rewrite' => array('slug' => 'newsletter'),'query_var' => false,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',)) );

Custom Taxonomies
register_taxonomy('countries','post',array( 'hierarchical' => false, 'label' => 'Countries','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => ),'singular_label' => 'Country') );

?>

#5 @ryno267
16 years ago

  • Keywords RC3 post types added
  • Priority changed from normal to high
  • Severity changed from normal to major

having a very similar issue w/ RC3. Custom post types work fine on default /?type=post-name-here but 404 when permalinks enabled. Code entails:

add_action('init', 'events_post_type');
function events_post_type() {
	$args = array(
		'label' => _('Events'),
		'singular_label' => _('Event'),
		'public' => true,
		'show_ui' => true,
		'capability_type' => 'post',
		'hierarchical' => true,
		'rewrite' => array(
	    	'slug' => 'events',
			'with_front' => false,
		),
		'supports' => array('title', 'thumbnail', 'editor', 'custom-fields', 'excerpt', 'page-attributes')
		);
	register_post_type('events', $args);
	register_taxonomy_for_object_type('event_type', 'events');
	register_taxonomy_for_object_type('post_tag', 'events');
}

#6 @ocean90
16 years ago

  • Keywords reporter-feedback added; RC3 post types removed
  • Priority changed from high to normal
  • Severity changed from major to normal

Do you have refreshed the permalinks? (Refresh = Visit Settings -> Permalinks and save again).
It works for me.

#7 @ryno267
16 years ago

@ocean90 I have, many times. .com/events/postname-here/ does not work regardless of what I try. Tried another name for post type too like /testimonials/postname-here/ and that didn't work either.

#8 @dd32
16 years ago

add this to a plugin or theme file and post the result here, Without seeing the contents of your rewrite rules its a bit hard to work out where the issue could be.

echo "<pre>";
print_r(get_option('rewrite_rules'));

#9 @ryno267
16 years ago

  • Cc ryno267 added

So here's an update. Nothing I did including the sequence sivel told me to run in order to get it to flush worked (sequence: enable new theme, visit permalinks page, add new post to custom post type, visit permalinks page)

I setup a brand new install locally, added the theme, enabled permalinks and added a post to each of my two custom post types. They worked fine locally. I exported users and posts from old live site into new local one and then did the same for pages. All was working fine locally.

Dropped database for online site, and imported the one I was using locally, updated the home and site domain and tested... WHOA permalinks worked! Was stoked. I made a new backup of that database of the online working site.

Then: I added a couple more posts in one of the custom post types and it broke permalinks for all custom post types. None of the refresh techniques worked. I restored to the last working database backup that I made RIGHT BEFORE this and the custom post type urls still 404'd. Whatever happened killed it, and it's not something in the database.

The Rewrite Rules dump is here:

Array
(
    [premium/(.+?)/?$] => index.php?get_premium_file=$matches[1]
    [robots\.txt$] => index.php?robots=1
    [.*wp-atom.php$] => index.php?feed=atom
    [.*wp-rdf.php$] => index.php?feed=rdf
    [.*wp-rss.php$] => index.php?feed=rss
    [.*wp-rss2.php$] => index.php?feed=rss2
    [.*wp-feed.php$] => index.php?feed=feed
    [.*wp-commentsrss2.php$] => index.php?feed=rss2&withcomments=1
    [feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]
    [(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]
    [page/?([0-9]{1,})/?$] => index.php?&paged=$matches[1]
    [comments/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]&withcomments=1
    [comments/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]&withcomments=1
    [comments/page/?([0-9]{1,})/?$] => index.php?&paged=$matches[1]
    [search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?s=$matches[1]&feed=$matches[2]
    [search/(.+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?s=$matches[1]&feed=$matches[2]
    [search/(.+)/page/?([0-9]{1,})/?$] => index.php?s=$matches[1]&paged=$matches[2]
    [search/(.+)/?$] => index.php?s=$matches[1]
    [category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
    [category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
    [category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
    [category/(.+?)/?$] => index.php?category_name=$matches[1]
    [tag/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
    [tag/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
    [tag/(.+?)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
    [tag/(.+?)/?$] => index.php?tag=$matches[1]
    [author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$matches[1]&feed=$matches[2]
    [author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$matches[1]&feed=$matches[2]
    [author/([^/]+)/page/?([0-9]{1,})/?$] => index.php?author_name=$matches[1]&paged=$matches[2]
    [author/([^/]+)/?$] => index.php?author_name=$matches[1]
    [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]
    [([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
    [([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
    [([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]
    [([0-9]{4})/([0-9]{1,2})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]
    [([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&feed=$matches[2]
    [([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&feed=$matches[2]
    [([0-9]{4})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&paged=$matches[2]
    [([0-9]{4})/?$] => index.php?year=$matches[1]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [([0-9]{4})/([0-9]{1,2})/([^/]+)/trackback/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&tb=1
    [([0-9]{4})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&feed=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&feed=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&paged=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&cpage=$matches[4]
    [([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&page=$matches[4]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/?$] => index.php?attachment=$matches[1]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&cpage=$matches[3]
    [([0-9]{4})/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&cpage=$matches[2]
    [.+?/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [.+?/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [(.+?)/trackback/?$] => index.php?pagename=$matches[1]&tb=1
    [(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
    [(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
    [(.+?)/page/?([0-9]{1,})/?$] => index.php?pagename=$matches[1]&paged=$matches[2]
    [(.+?)/comment-page-([0-9]{1,})/?$] => index.php?pagename=$matches[1]&cpage=$matches[2]
    [(.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
)

Just to be updated... running RC3 and all plugins were the same locally as there were on live site. I eliminated as many 'different' things as I possibly could think of.

#10 @ryno267
16 years ago

and looking at that dump it's not being written to the rewrite_options... or so it seems

#11 @ryno267
16 years ago

Dump of local DB includes

[events/[^/]+/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [events/[^/]+/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [events/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [events/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [events/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [events/([^/]+)/trackback/?$] => index.php?events=$matches[1]&tb=1
    [events/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?events=$matches[1]&feed=$matches[2]
    [events/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?events=$matches[1]&feed=$matches[2]
    [events/([^/]+)/page/?([0-9]{1,})/?$] => index.php?events=$matches[1]&paged=$matches[2]
    [events/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?events=$matches[1]&cpage=$matches[2]
    [events/([^/]+)(/[0-9]+)?/?$] => index.php?events=$matches[1]&page=$matches[2]
    [events/[^/]+/([^/]+)/?$] => index.php?attachment=$matches[1]
    [events/[^/]+/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [events/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [events/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [events/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [testimonial/[^/]+/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [testimonial/[^/]+/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [testimonial/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [testimonial/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [testimonial/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [testimonial/([^/]+)/trackback/?$] => index.php?testimonials=$matches[1]&tb=1
    [testimonial/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?testimonials=$matches[1]&feed=$matches[2]
    [testimonial/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?testimonials=$matches[1]&feed=$matches[2]
    [testimonial/([^/]+)/page/?([0-9]{1,})/?$] => index.php?testimonials=$matches[1]&paged=$matches[2]
    [testimonial/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?testimonials=$matches[1]&cpage=$matches[2]
    [testimonial/([^/]+)(/[0-9]+)?/?$] => index.php?testimonials=$matches[1]&page=$matches[2]
    [testimonial/[^/]+/([^/]+)/?$] => index.php?attachment=$matches[1]
    [testimonial/[^/]+/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [testimonial/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [testimonial/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [testimonial/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]

SO why is that getting deleted when adding new posts ???

#12 @dd32
16 years ago

According to that dump there, No custom post types were registered at the time of the rules being generated.

You should see a section at the start of:

  'events/.+?/attachment/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
  'events/.+?/attachment/([^/]+)/trackback/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
  'events/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
  'events/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
  'events/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpage=$matches[2]' (length=50)
  'events/(.+?)/trackback/?$' => string 'index.php?events=$matches[1]&tb=1' (length=33)
  'events/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?events=$matches[1]&feed=$matches[2]' (length=45)
  'events/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?events=$matches[1]&feed=$matches[2]' (length=45)
  'events/(.+?)/page/?([0-9]{1,})/?$' => string 'index.php?events=$matches[1]&paged=$matches[2]' (length=46)
  'events/(.+?)/comment-page-([0-9]{1,})/?$' => string 'index.php?events=$matches[1]&cpage=$matches[2]' (length=46)
  'events/(.+?)(/[0-9]+)?/?$' => string 'index.php?events=$matches[1]&page=$matches[2]' (length=45)

Can you disable whatever you're using to get the /premium/.../ links and try again? perhaps thats breaking the rule generation somehow..

To confirm, The code you posted higher up, is in the direct plugin file, you're not using multisite, and that it doesnt work with the default theme and all other plugins disabled?

Also, Are you using any database caching layers? Or any object cache files? (Look under Plugins -> Dropins )

#13 @ryno267
16 years ago

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

"MemberWing Membership Website Premium P1 Edition" seems to be adding that premium rewrite rule... and that does seem to be the issue after adding a couple new posts and they seem fine.

sunova... no clue it was doing anything with permalinks... local was fine tho... ? But I'll take this up with plugin dev. sigh

#14 @ocean90
16 years ago

  • Keywords reporter-feedback removed
  • Milestone Unassigned deleted

Thx for you investigations.

Note: See TracTickets for help on using tickets.