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. Filtering options will be in the View builder with links for Filter entries and Sort entries. In order to create a filter, simply click the "+Add filter" 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, edit your View and click the Filter Entries link. Add 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 View builder that says "User 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.
By User Meta
If you have the Formidable Forms add-on for WordPress User Registration, you can filter a view by user meta stored in a user's profile. For example, if you have an "Age" field in your form and your user's have a user meta field for "Age" stored in their profile, you could add a filter like the following to only show results where the user's age matches the age stored in the entry:
Age is equal to [user_meta key=user_age]
Replace "user_age" with the appropriate key for the respective user meta from the user's profile.
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']-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.
If you want to display additional info in the view if the entry is a draft, you can use the [if is_draft] conditional.
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.
No results on WPEngine
When many entries are included in the results, there is a possibility WPEngine servers will stop the query. When this happens, no results are returned and the view will display the 'No Entries' message.
To prevent this from happening, add this in your wp-config.php:
define( 'WPE_GOVERNOR', false );
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.
Filter by user group
This example filters by user meta to display the correct form entries. Let’s say you have a form that is shared between two groups, and you want to filter the entries accessed by each group. You can do this by following the steps below:
- Each user should have a group name saved in a custom field on the user profiles. If this isn't already saved, you can add it using a user registration or profile form.
- Add a hidden field in the form used for collecting entries for display.
- Set the default value to the group name from the user profile with the [user_meta] shortcode.
- In the View Builder → Filter Entries section, add a filter like the following. This will only show results where the user's group matches the group name stored in the entry.
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.
If you want to build if statements in a View to check if the current user is the owner/creator of the entry, use the frmpro_fields_replace_shortcodes hook.