﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
19241	custom post type with extra rewrite rules doesnt work with permalin structure with %category%	moz667	duck_	"I have registered a custom post type with an extra rewrite rule. When I set the permalink structure with %category% and access to the post type custom permalink structure (including the extra rule) allways get redirect to the post type itselfs.

To get the error follow this instructions:

1. Install and activate this plugin (it register the custom post type and the extra rewrite rules

{{{
<?php 
/*
Plugin Name: Post Type Businesses Lists Bug
Plugin URI: http://example.com/
Description: 
Version: 0.0.1
Author: moz667
Author URI: http://example.com/
*/

add_action(""init"", ""register_post_type_bss_list"");
function register_post_type_bss_list() {
	$args = array(
		""labels"" => array(""name"" => __(""Businesses Lists"")),
		""public"" => true,
		""show_ui"" => true, 
		""show_in_menu"" => true, 
		""query_var"" => true,
		""rewrite"" => array(""slug"" => ""bss-lists"", ""with_front"" => false ),
		""capability_type"" => ""bss_list"",
		""has_archive"" => true, 
		""supports"" => array(""title"", ""editor"")
	);
	
	register_post_type(""bss_list"", $args);
	
	$rules = get_option( ""rewrite_rules"" );
	
   	if ( !isset($rules[""bss-lists/?$""])) {
   		flush_rewrite_rules();
   	}
}

add_action(""wp_loaded"",""bl_flush_rules"" );
function bl_flush_rules() {
	$rules = get_option( ""rewrite_rules"" );
	
	if (!isset( $rules[""bss-lists/(.+?)/detail/(.+?)$""]) ) {
		flush_rewrite_rules();
	}
}

add_action(""generate_rewrite_rules"", ""bl_rewrite_rules"");
function bl_rewrite_rules($wp_rewrite) {
	$new_rules = array(
		""bss-lists/(.+?)/detail/(.+?)$"" => 'index.php?bss_list=$matches[1]&bssname=$matches[2]'
	);
	
	$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

add_filter(""query_vars"", ""bl_query_vars"");
function bl_query_vars($public_query_vars) {
	$public_query_vars[] = ""bssname"";
	
	return $public_query_vars;
}

register_deactivation_hook( __FILE__, ""bl_deactivate"" );
function bl_deactivate() {
	flush_rewrite_rules();
}

add_filter(""the_content"", ""bl_the_content"");
function bl_the_content($content = """") {
	global $wp;
	
	if (isset($wp->query_vars[""bssname""])) {
		$content = ""<p>SOME DETAIL CONTENT FOR "" . $wp->query_vars[""bssname""] . ""</p>"";
	} else {
		$post = get_post(get_the_ID());
	}
	
	if ($post && $post->post_type == ""bss_list"") {
		$content = ""<h4><a href=\"""" . get_permalink() . ""detail/sample-detail/\"">Some detail link</a></h4>"" . $content;
	}
	
	return $content;
}
}}}

2. Set up the permalink structure at as : /%category%/%postname%/%post_id%/

3. Add a new post type bss_list and publish it.

4. Access to the view of the new post type bss_list.

5. Click on ""Some detail link"", it is a link to a http://yourtestsite.com/bss-lists/your-new-bss-list/detail/sample-detail/ . You'll see how it is redirect to the custom post type again : http://yourtestsite.com/bss-lists/your-new-bss-list/

If you change de permalink structure to /%year%/%postname%/%post_id%/ it works properly, so I think that the %category% tag is the reason of the fail

I have been testing everything for a week, if you could help me I will be really grateful
"	defect (bug)	closed	normal	3.4	Canonical	3.0	normal	fixed		
