[wp-trac] [WordPress Trac] #19241: custom post type with extra rewrite rules doesnt work with permalin structure with %category%
WordPress Trac
wp-trac at lists.automattic.com
Mon Nov 14 18:55:54 UTC 2011
#19241: custom post type with extra rewrite rules doesnt work with permalin
structure with %category%
--------------------------+-----------------------------
Reporter: moz667 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
--------------------------+-----------------------------
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
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19241>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list