This function can be used to make WordPress aware of custom querystring variables. Generally, it's used in combination with add_rewrite_rule() to create rewrite rules for pages with custom templates.
If you use this function to declare a rewrite tag that already exists, the existing tag will be overwritten.
This function must be called on init or earlier.
<?php add_rewrite_tag($tag, $regex, $query); ?>
The following will register a tag called 'film_title':
<?php
function custom_rewrite_tag() {
add_rewrite_tag('%film_title%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
?>
This is particularly important when you are using rewrites with custom page templates.
With a rewrite tag defined, you can now retrieve the value of your rewritten querystring variables using WordPress's $wp_query variable. To get the value of the above tag out of a rewrite, you could use the following in your page template:
$wp_query->query_vars['film_title']
Note that using $_GET on a rewritten URL will not work, even if the rewrite includes the querystring variables. You must use $wp_query.
add_rewrite_tag() is located in wp-includes/rewrite.php
.