I have a set of variable set up, created with add_filter in my plugin functions file:
add_filter('query_vars', 'user_country_var' );
add_filter('query_vars', 'user_lat_var' );
add_filter('query_vars', 'user_lon_var' );
This is then referenced by some code which I used to process the filters. This worked fine when the code was just chucked into a template file. I'm trying to tidy things up and I'm stumped.
I've put the following function in a class, it's currently called at init, and is definitely there (sits alongside some other code that works fine). But it's just not getting the variables from my url, and so is outputting the fallback, 'your country':
// pull variable from url
if (isset($wp_query->query_vars['country']))
{
$this->user_country = $wp_query->query_vars['country'];
}
else { $this->user_country = 'your country'; }
if (isset($wp_query->query_vars['lat']))
{
$this->user_lat = $wp_query->query_vars['lat'];
}
else { $this->user_lat = '52.5'; }
if (isset($wp_query->query_vars['lon']))
{
$this->user_lon = $wp_query->query_vars['lon'];
}
else { $this->user_lon = '13.4'; }
Is there any reason this shouldn't be able to get the variables? As I said, it sets the default of the class's public variables fine and is executed. It's just not getting the variables even when they're there...
I can post more code if it helps, or indeed clarify. Thanks in advance for any ideas!