WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have in my themes some code which will set a session variable. For the sake of example, it's a geolocation routine which will set to either USA, UK or ROW, resulting in:

$_SESSION['region'] = 'USA';

and I have a custom taxonomy of 'regionok' which any or all of the same terms are set.

I wish to use the session variable value as the taxonomy term to filter on.

The cleanest solution I can imagine would be to have a filter hook in my functions.php which would replace the placeholder term 'auto-region' with the session value before each query is executed. That way I can use widget plugins without having to hack them - I would just use the placeholder term in configuration. However, I don't know what the relevant hook would be.

(Other use cases would be session variables for family filter, referrer, etc. The geolocation example is entirely incidental.)

share|improve this question
up vote 1 down vote accepted

If you want to apply this term filter to all queries on the site, then you'll want to use the 'parse_query' action. This action will accept the WP_Query instance as a parameter, which will allow you to add a term filter based on the $_SESSION variable.

share|improve this answer
Yep. That works. Ta. – Paul Gregory Jan 10 '12 at 22:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.