What is a filter? A filter allows you to display form entries that meet specific criteria. For example, if you had customers and employees give feedback on a product in a form, you could filter out the customers' feedback, leaving only the employees' feedback displayed in the View.
When filtering entries, you can apply multiple filters to a single View. The result will only display entries that meet all filters. For example, if you have the filters listed here...
...your View will only display entries where the Last Name is equal to "Doe" AND the First Name is equal to "Jane".
If you would like to create a basic filter, you can do so by going into edit a View and scrolling to the bottom of the page. Filtering options will be in the "Advanced Settings" section under "Sort and Filter." In order to create a filter, simply click the "+Add" button. This will create a new filter which you can customize to fit your needs.
It can be very helpful to filter Views based on parameters in the URL, the current user, date ranges, etc.
By Current User
If you would like to allow your users to see only their submitted entries, go into your View and in the Advanced Settings at the bottom, set a filter that says "User ID is equal to current_user". This will only work if you have a User ID field in your form.
You may pass parameters to a View through the URL or through the View shortcode. If you would like to filter entries based on a parameter, add a filter that says "Specific field is equal to [get param="param_name"]". By default, a filter will be ignored if the parameter is not set or if the parameter value is blank. If you would like to prevent entries from showing when the parameter is not set, you can add the default option to your filter like this: [get param="param_name" default="none"]. The ability to filter by a URL parameter is often used when creating advanced search forms.
By User ID
You may want to create a view that an administrator can select a User to filter entries by to only see the entries of a selected user. This is similar to filtering by parameter, because you will need a separate search form.
- Create a search form. This form will have a single User ID field, and will redirect to the view on submit. Set the Redirect to URL to yoursite.com/your-page/?my-user=[x] where x is the User ID field ID.
- Add this filter so that User ID fields will display as dropdowns on the front-end.
- Create a view from the form from which you want to view user's entries.
- Add a filter in the advanced settings that says "Entry ID is equal to [get param=my-user]"
- Publish the view.
Now you can select a User in the User ID search form and view their entries for a specific form.
You may filter entries by the date they were created or updated. You may also filter entries by a date field in your form. When filtering by date, you may use any date string that is accepted by the PHP strtotime() function. The following are commonly used date strings:
- NOW: Get the current date and time. You can use [date format='Y-m-d H:i:s'] as an alternative.
- 2016-01-31: Insert any date in the Y-m-d format.
- Next Thursday: Get the date for next Thursday.
- Last Monday: Get the date for last Monday.
- first day of this year: Get the first or last day of the year, month, or week. Use 'first' or 'last', along with 'year', 'month', or 'week'. PHP requires English for turning phrases like this into a date.
- +1 day: Get the date by going back or forward by day. Use + to go forward and - to go backward.
- +1 week: Get the date by going back or forward by week. Use + to go forward and - to go backward.
- +1 year: Get the date by going back or forward by year. Use + to go forward and - to go backward.
- +1 week 2 days 4 hours 2 seconds: Get the date with any combination of weeks, days, hours, and/or seconds.
- [date format='Y-m-d']-01-01: Get the first day of the current year without English. This example is the same as 2019-01-01. Or the first day of the current month is [date format='Y-m']-01.
If you would like to only show upcoming events, add a filter that says "Date field is greater than NOW". If you would like to show entries that were created in the past week, add a filter that says "Creation date is greater than -1 week". Please note that if you choose to filter by a specific date, you must use the "Y-m-d" date format in the View filter.
By Entry Status
If you have a a mixture of draft entries and complete entries, you may filter the entries by their entry status. By default, a View will include complete entries. You can filter by any of the following:
- Draft or complete entry: This will include both drafts and complete entries.
- Draft: This will include only draft entries.
- Complete entry: This will include only complete entries.
When using filters, if you find that your entries are not being filtered correctly, here are a few things to check:
- Check to ensure there are entries that exist which meet all filters.
- If you are filtering from parameters in a URL, check the URL. Do the parameters appear and are they correct? If so, check if the parameters match up with the parameters set in your View filters.
- If you are searching a checkbox or multi-select dropdown field, are you searching for any values between 1 and 9? If so, the entries will not filter properly due to the serialization that occurs for checkbox and multi-select dropdown field values when saved to the database.
If you have reviewed the above steps and are not able to solve the problem, please post in the help desk for further assistance.
Show entries for the upcoming week
Imagine you have a form that tracks appointments, and you want to show entries for the upcoming week. Simply add two filters: "Date field is greater than NOW" and "Date field is less than +1 week".
Show all entries submitted by due date
Let's say that you have a form that has a deadline, and you want to display all entries that were submitted or updated before the set deadline. You can do so by setting up your filters like this.
If you need to customize your View filters with PHP, you may use the frm_where_filter hook or the frm_filter_where_val hook. Please be aware that we do not recommend using custom PHP if you are not comfortable writing and debugging PHP.