I'm sure this must be fairly simple but can't figure out how to do it.
I have a page with it's own template, say mysite.com/custom. This page is handled by custom.php.
How can I set it up so that mysite.com/custom/anything is handled by custom.php?var=anything
I just need whatever comes after custom/ passing to custom.php as a string, no matter what it is.
If say your trying to find a variable being passed to it
http://yourdomain.tld/custom/?somevar=weirdo
There are actually several different methods to do this, you can find and validate the $_REQUEST
for example:
if (isset($_REQUEST['somevar'])) $somevar = esc_attr($_REQUEST['somevar']);
Or the WP prefered method where you check if the get_query_var has it.
http://codex.wordpress.org/Function_Reference/get_query_var
I just do this:
if (isset($wp_query->query_vars['somevar'])) $somevar = esc_attr($wp_query->query_vars['somevar']);
Thanks for your response. Sorry, I didn't explain what I meant properly.
The problem is not for custom.php to find variables that have been passed to it. It's getting mysite.com/custom/any-random-stuff/with-slashes-etc to be handled by custom.php?var=any-random-stuff/with-slashes-etc
Ah you need to create some rewrite rules to handle those
http://codex.wordpress.org/Function_Reference/WP_Rewrite
This allows you to create a new ruleset to use with custom permalinks
Thanks again. I'm still a bit unclear on the usage of WP Rewrite. Do the functions there need to be run once, to update wordpress' rewrite rules? Where should they be run from?