Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.