[wp-trac] [WordPress Trac] #10616: post queries are not working with custom permalinks
WordPress Trac
wp-trac at lists.automattic.com
Fri Aug 14 21:19:59 UTC 2009
#10616: post queries are not working with custom permalinks
--------------------------+-------------------------------------------------
Reporter: frumph | Owner:
Type: defect (bug) | Status: new
Priority: high | Milestone: Unassigned
Component: Template | Version: 2.8.4
Severity: major | Keywords:
--------------------------+-------------------------------------------------
Comment(by filosofo):
Replying to [comment:4 frumph]:
{{{
parse_str(preg_replace('#^.*\?#', '', $_SERVER['REQUEST_URI']),
$query_vars);
}}}
I think you're taking a security risk by parsing arbitrary request
arguments.
A better way is to use the WordPress rewrite API.
Attach something like the following to the "init" action, and trigger a
flush of the rewrite rules (one way to do that is to visit the admin
permalinks page).
{{{
add_rewrite_rule('^archives-year/(.*)/?$',
'index.php?archive_year=$matches[1]', 'top');
add_rewrite_tag('%archive_year%', '(.*)');
}}}
The first line prepares the rewrite rule so it will be added to the rules
after the flush. The second makes WP and WP_Query aware that archive_year
is a query argument.
Depending on what you're trying to do, the existing "year" query variable
might be sufficient instead of the custom "archive_year". In that case,
you could just do
{{{
add_rewrite_rule('^archives-year/(.*)/?$', 'index.php?year=$matches[1]',
'top');
}}}
I suggest this be marked as "won't fix," as we shouldn't be querying based
on arbitrary request arguments, and the desired results can be obtained
with the existing API.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10616#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list