I'm trying to create a simple booking form. The are four options on a separate page (group, corporate, student and venue).
For example: If the user clicks Book Now for Group Experience it should take them to a dynamic page containing the form with the query string 'Group-Experience'. This query string will be used for the value of the subject field.
Now the problem, At the moment this is what I have:
URL: /book/?menu=group-experience
subject field: "group-experience".
I would like:
URL: /book/group-experience
subject field: "Group Experience"
I've got it so the '-' is removed with:
< ?php
$menu = str_replace ( "-", " ", $_GET['menu']);
?>
I've looked around Stackoverflow and other websites but can't find a method that works alongside WordPress - The form is inside a template file.
My current .htaccess:
< IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /lab/foodfiendexp/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /lab/foodfiendexp/index.php [L]
< /IfModule>
You must add a page rewrite rule, to do that add the following code to functions.php
add_filter( 'page_rewrite_rules', 'book_page_rewrite_rules' );
function book_page_rewrite_rules( $rewrite_rules )
{
end( $rewrite_rules );
$last_pattern = key( $rewrite_rules );
$last_replacement = array_pop( $rewrite_rules );
$rewrite_rules += array(
'(.+?)/([^/]+)/?$' => 'index.php?pagename=$matches[1]&menu=$matches[2]',
$last_pattern => $last_replacement,
);
return $rewrite_rules;
}
add_rewrite_tag('%menu%','([^&]+)');
Then update the permalink structure from Settings -> Permalinks, you just hit save again.
And you access your menu with
$menu = get_query_var('menu');
Now you url should work with
/book/group-experience
considering book is a page, if you need to add the rewrite rule to a post, change it to a post rewrite rule
More details here: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
Also, if you need an rewrite rule inspector, this plugin is very very good: http://wordpress.org/plugins/monkeyman-rewrite-analyzer/