Extracting a parameter from a URL in WordPress
php, wordpress
Solution
When passing parameters through the URL you're able to retrieve the values as GET parameters.
Use this:
$variable = $_GET['param_name'];
//Or as you have it
$ppc = $_GET['ppc'];
It is safer to check for the variable first though:
if (isset($_GET['ppc'])) {
$ppc = $_GET['ppc'];
} else {
//Handle the case where there is no parameter
}
Here's a bit of reading on GET/POST params you should look at: http://php.net/manual/en/reserved.variables.get.php
EDIT: I see this answer still gets a lot of traffic years after making it. Please read comments attached to this answer, especially input from @emc who details a WordPress function which accomplishes this goal securely.
Problem
I am trying to pass a parameter to a WordPress site using a URL - for instance: `www.fioriapts.com/?ppc=1` will be the URL. I am intending to write a function in the functions.php file but the mechanics of how to extract a parameter in WordPress is beyond me. How can it be done? I am finding a lot of examples on how to add a parameter to a URL using the function `add_query_arg()` but have found nothing on how to extract a parameter.