Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
Use a spacebar or arrow keys to navigate
WP_Rewrite
Isn't As Scary As You ThinkWP_Rewrite
Give Us?
http://ethitter.com/2013/08/year-in-review/
vs
http://ethitter.com/?p=3886
Instead, it's all about Regular Expressions.
WordPress uses the chosen Permalink structure to build Regular Expressions that translate a pretty permalink to arguments for WP_Query
.
/2013/08/year-in-review/
becomes:
array(
'year' => '2013',
'month' => '08',
'name' => 'year-in-review',
)
In the database, specifically the options
table.
The array of rewrite rules are stored in an option named rewrite_rules
.
"([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$"
=>
"year=$matches[1]&monthnum=$matches[2]
&name=$matches[3]&page=$matches[4]"
You're in luck, WP provides lots of options!
add_rewrite_rule()
add_rewrite_endpoint()
generate_rewrite_rules
actionrewrite_rules_array
filter
Not an exhaustive list
add_rewrite_rule()
add_rewrite_rule( $regex, $redirect, $position )
add_rewrite_rule(
"([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$",
"year=$matches[1]&monthnum=$matches[2]
&name=$matches[3]&page=$matches[4]",
"top"
)
add_rewrite_endpoint()
add_rewrite_endpoint( $endpoint )
add_rewrite_endpoint( 'feed' )
add_rewrite_endpoint( 'print' )
WP_Rewrite
behaviour
Use the generate_rewrite_rules
action.
WP_Rewrite
object.
Use the rewrite_rules_array
filter.