[wp-trac] [WordPress Trac] #16687: %postname% permalinks should not trigger verbose rewrite rules
WordPress Trac
wp-trac at lists.automattic.com
Mon Jul 11 20:36:58 UTC 2011
#16687: %postname% permalinks should not trigger verbose rewrite rules
-----------------------------+------------------
Reporter: nacin | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: 3.3
Component: Rewrite Rules | Version:
Severity: normal | Resolution:
Keywords: |
-----------------------------+------------------
Comment (by Otto42):
How to make verbose page rules less painful.
For the cases that would normally invoke verbose_page_rules, use this
mechanism instead:
1. Move the page rewrite rule immediately above normal post custom rewrite
rules in the rewrite_rules.
2. Special case the page rewrite rule to use a callback or something to do
the following:
a. Split the url along slashes (post_name's can't contain slashes).
Reverse number them. So they look like this: page4/page3/page2/page1 (the
page you want, page1, is always at the beginning of your list.
b. Recursive subquery fun!
{{{
select ID from wp_posts where post_name = page1 AND post_parent =
( select ID from wp_posts where post_name = page2 AND post_parent =
( select ID from wp_posts where post_name = page3 AND post_parent =
( select ID from wp_posts where post_name = page4
)
)
)
}}}
Note that this is actually pretty fast due to indexing, although if
somebody decides to go too deep into the dream state, they could fall into
limbo.
Alternative could use joins. Limbo here is a lot deeper down, probably.
{{{
SELECT ID FROM wp_posts a
JOIN wp_posts b ON a.post_parent = b.ID AND post_name = page2
JOIN wp_posts c ON b.post_parent = c.ID AND post_name = page3
JOIN wp_posts d ON c.post_parent = d.ID AND post_name = page4
WHERE a.post_name = page1
}}}
c. If this post exists, check its post_type for page and set vars
accordingly. If post_type is attachment, check parent's type instead (to
handle page attachments).
d. If post does not exist, then fail and get on with life.
Advantage: This adds one extra (ugly) query to the case of using verbose
page rules, and doesn't require all the verbose rules to be so verbose. It
moves the performance issue to this one query only, and the performance
issue here is keyed to the depth of nested pages instead of to the total
number of pages. Log N improvement for most all cases.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16687#comment:29>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list