Opened 15 years ago
Closed 14 years ago
#10446 closed defect (bug) (wontfix)
Rewrite rules are not flushed when a New taxonomy is created
Reported by: | sirzooro | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8.1 |
Component: | Taxonomy | Keywords: | needs-patch |
Focuses: | Cc: |
Description
The code:
class TestPlugin { function TestPlugin() { add_action( 'init', array( &$this, 'init' ) ); } function init() { register_taxonomy( 'mytax', 'post', array('label' => 'My Tax', 'query_var' => false, 'rewrite' => true ) ); } } $wp_test_plugin = new TestPlugin();
This plugin registers new taxonomy. It appears in Menu and on Edit Post page. Assigned values are also displayed by the_taxonomies()
. One thing which does not work are permalinks. WP generates URLs like http://wordpress.local/mytax/test/
, but they don't work - error 404. What's more, it looks that rewriting rules are registered correctly. I tried to call $wp_rewrite->rewrite_rules()
just after registering taxonomy, and new rules are in place as expected:
'mytax/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?taxonomy=mytax&term=$1&feed=$2' (length=40) 'mytax/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?taxonomy=mytax&term=$1&feed=$2' (length=40) 'mytax/([^/]+)/page/?([0-9]{1,})/?$' => string 'index.php?taxonomy=mytax&term=$1&paged=$2' (length=41) 'mytax/([^/]+)/?$' => string 'index.php?taxonomy=mytax&term=$1' (length=32)
Change History (11)
#2
@
15 years ago
Sure. BTW, I use following permalink format: /%year%/%monthnum%/%postname%/
.
'mytax/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?taxonomy=mytax&term=$1&feed=$2' (length=40) 'mytax/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?taxonomy=mytax&term=$1&feed=$2' (length=40) 'mytax/([^/]+)/page/?([0-9]{1,})/?$' => string 'index.php?taxonomy=mytax&term=$1&paged=$2' (length=41) 'mytax/([^/]+)/?$' => string 'index.php?taxonomy=mytax&term=$1' (length=32) 'robots\.txt$' => string 'index.php?robots=1' (length=18) '.*wp-atom.php$' => string 'index.php?feed=atom' (length=19) '.*wp-rdf.php$' => string 'index.php?feed=rdf' (length=18) '.*wp-rss.php$' => string 'index.php?feed=rss' (length=18) '.*wp-rss2.php$' => string 'index.php?feed=rss2' (length=19) '.*wp-feed.php$' => string 'index.php?feed=feed' (length=19) '.*wp-commentsrss2.php$' => string 'index.php?feed=rss2&withcomments=1' (length=34) 'feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$1' (length=18) '(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$1' (length=18) 'page/?([0-9]{1,})/?$' => string 'index.php?&paged=$1' (length=19) 'comment-page-([0-9]{1,})/?$' => string 'index.php?&page_id=2&cpage=$1' (length=29) 'comments/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$1&withcomments=1' (length=33) 'comments/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$1&withcomments=1' (length=33) 'comments/page/?([0-9]{1,})/?$' => string 'index.php?&paged=$1' (length=19) 'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?s=$1&feed=$2' (length=22) 'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?s=$1&feed=$2' (length=22) 'search/(.+)/page/?([0-9]{1,})/?$' => string 'index.php?s=$1&paged=$2' (length=23) 'search/(.+)/?$' => string 'index.php?s=$1' (length=14) 'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?category_name=$1&feed=$2' (length=34) 'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?category_name=$1&feed=$2' (length=34) 'category/(.+?)/page/?([0-9]{1,})/?$' => string 'index.php?category_name=$1&paged=$2' (length=35) 'category/(.+?)/?$' => string 'index.php?category_name=$1' (length=26) 'tag/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?tag=$1&feed=$2' (length=24) 'tag/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?tag=$1&feed=$2' (length=24) 'tag/(.+?)/page/?([0-9]{1,})/?$' => string 'index.php?tag=$1&paged=$2' (length=25) 'tag/(.+?)/?$' => string 'index.php?tag=$1' (length=16) 'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?author_name=$1&feed=$2' (length=32) 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?author_name=$1&feed=$2' (length=32) 'author/([^/]+)/page/?([0-9]{1,})/?$' => string 'index.php?author_name=$1&paged=$2' (length=33) 'author/([^/]+)/?$' => string 'index.php?author_name=$1' (length=24) '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&day=$3&feed=$4' (length=44) '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&day=$3&feed=$4' (length=44) '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => string 'index.php?year=$1&monthnum=$2&day=$3&paged=$4' (length=45) '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => string 'index.php?year=$1&monthnum=$2&day=$3' (length=36) '([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&feed=$3' (length=37) '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&feed=$3' (length=37) '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => string 'index.php?year=$1&monthnum=$2&paged=$3' (length=38) '([0-9]{4})/([0-9]{1,2})/?$' => string 'index.php?year=$1&monthnum=$2' (length=29) '([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&feed=$2' (length=25) '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&feed=$2' (length=25) '([0-9]{4})/page/?([0-9]{1,})/?$' => string 'index.php?year=$1&paged=$2' (length=26) '([0-9]{4})/?$' => string 'index.php?year=$1' (length=17) '[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$' => string 'index.php?attachment=$1' (length=23) '[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => string 'index.php?attachment=$1&tb=1' (length=28) '[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => string 'index.php?attachment=$1&cpage=$2' (length=32) '([0-9]{4})/([0-9]{1,2})/([^/]+)/trackback/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&tb=1' (length=42) '([0-9]{4})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&feed=$4' (length=45) '([0-9]{4})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&feed=$4' (length=45) '([0-9]{4})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&paged=$4' (length=46) '([0-9]{4})/([0-9]{1,2})/([^/]+)/comment-page-([0-9]{1,})/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&cpage=$4' (length=46) '([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$' => string 'index.php?year=$1&monthnum=$2&name=$3&page=$4' (length=45) '[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/?$' => string 'index.php?attachment=$1' (length=23) '[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$' => string 'index.php?attachment=$1&tb=1' (length=28) '[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => string 'index.php?attachment=$1&cpage=$2' (length=32) '([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$' => string 'index.php?year=$1&monthnum=$2&cpage=$3' (length=38) '([0-9]{4})/comment-page-([0-9]{1,})/?$' => string 'index.php?year=$1&cpage=$2' (length=26) '.+?/attachment/([^/]+)/?$' => string 'index.php?attachment=$1' (length=23) '.+?/attachment/([^/]+)/trackback/?$' => string 'index.php?attachment=$1&tb=1' (length=28) '.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$1&feed=$2' (length=31) '.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => string 'index.php?attachment=$1&cpage=$2' (length=32) '(.+?)/trackback/?$' => string 'index.php?pagename=$1&tb=1' (length=26) '(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?pagename=$1&feed=$2' (length=29) '(.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?pagename=$1&feed=$2' (length=29) '(.+?)/page/?([0-9]{1,})/?$' => string 'index.php?pagename=$1&paged=$2' (length=30) '(.+?)/comment-page-([0-9]{1,})/?$' => string 'index.php?pagename=$1&cpage=$2' (length=30) '(.+?)(/[0-9]+)?/?$' => string 'index.php?pagename=$1&page=$2' (length=29)
#3
@
15 years ago
Did you flush your rewrite rules? New rules do not function until the old ones are flushed, which you can do by calling $wp_rewrite->flush_rules()
.
#4
@
15 years ago
No, and this helped - thanks. So it will be good if register_taxonomy()
could do it, or at least update documentation for this function to state this.
#5
@
15 years ago
register_taxonomy()
can't flush the rules, because it's called every time WP is loaded. For efficiency the rewrite rules should be flushed only when they change, as they're stored in the database.
#6
@
15 years ago
register_taxonomy() can't flush the rules,
Not directly, It'd be possible to flush the rules if the registered taxonomies changes however.. (ie. just store a list of the previously registered taxonomies and flush if it changes, Could be done on admin-access only as well)
Would also help clean up after taxonomies which do not flush the rules once they're no longer around.
#7
@
15 years ago
- Component changed from Permalinks to Taxonomy
- Milestone changed from 2.8.2 to Future Release
- Owner changed from ryan to filosofo
#8
@
15 years ago
this ticket is invalid. the plugin is likely missing activate and deactivate functions that proceed to flush the rewrite rules as needed.
#9
follow-up:
↓ 10
@
15 years ago
- Summary changed from Permalinks for custom taxonomies does not work to Rewrite rules are not flushed when a New taxonomy is created
Yes, We've already worked that out.
Now the ticket has moved onto adding some documentation for others on the issue, or possibly auto-flushing the rules when the taxonomy list changes.
#10
in reply to:
↑ 9
@
14 years ago
- Owner filosofo deleted
- Status changed from new to assigned
Not all taxonomies need rewrite rules, and I think the overhead involved in trying to calculate whether taxonomies have changed since the previous page load would make this undesirable.
#11
@
14 years ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from assigned to closed
I'm going to go ahead and wontfix this. It's the same way for custom post types now -- plugins need to learn to flush the rules on activation.
In the future, if we start storing something in the database for taxonomies and post types, then perhaps this will come up again. With this ticket at 10 months old, it's time to close it.
can you post the full contents of $wp_rewrite->rewrite_rules()?