Just today I have got a question about the chance to add prompts to the wordpress page in order to filter dinamically a particular view.
Due to lack of time I didn’t develop any administration interface to add input boxes, but it’s possible to achieve it by using the PHP Analytics’ variables.
1. A simple single value filter
First of all we create one or more variables that will dynamically change the where condition that refers to the query we want to be affected by the user input.
Then we modify the query itself to pick up values from the variable(s).
A PHP Analytics variable is initialized with a GET or a POST action, so in order to pass the user input to the variable we have to create an HTML form that contains an HTML input component with the same name of the variable (see the example below):
<form method="post">
<select name="country">
<option value="France">France</option> <option value="Germany">Germany</option> <option value="Greece">Greece</option> <option value="Italy">Italy</option> <option value="Portugal">Portugal</option> <option value="Spain">Spain</option> <option value="UK">UK</option></select>
<input id="button" name="button" type="submit" value="Submit" />
</form>
Then we just have to add to our WordPress page/post the HTML code above and the view it belongs to (see the example below).
|


