Posts table filters
The Filters option in Posts Table Pro allows you to display dropdown lists above the table which allow users to filter (i.e. search) the table by selecting an item from the list. This option is used to filter the posts contents of the table after it has loaded.
If you want to create tables listing specific posts based on their category, date, tag, custom field, etc. before the table loads, please refer to that article.
You can create filters for the following columns:
- Custom taxonomies
You cannot show filters for custom fields. This is because custom fields are designed to store unique data, and you should use custom taxonomies for data that is used for organizing and grouping posts. You can easily create custom taxonomies using our free Easy Post Types and Fields plugin.
How to add search filters
Using the table builder
Use the 'Filters' option in the table builder to select one of the following options:
- Disabled - No filters will appear above the table.
- Show based on columns in table - If your table contains columns for categories, tags, author or any custom taxonomy, then these will appear automatically as filters above the table.
- Custom - This option allows you to manually choose which filters to display above the table. When you select this, a dropdown appears so that you can add one or more filters.
In a shortcode
You can also enable filters directly in the
[posts_table_template id=""] shortcode. To do this, use the
filters shortcode option:
- To show filters based on the contents of the table, add
filters="true"to the shortcode. This will show all filterable columns as filters above your table.
- To specify exactly which filters are shown, regardless of the columns displayed, list the filters as a comma-separated list, e.g:
This example would show filters for categories and tags:
[posts_table columns="title,categories,tags" filters="true"]
This example would show two filters - categories and my_taxonomy (remembering to add tax: before the taxonomy slug):
Positioning the search filters
The filters are displayed above the table by default, but if you have positioned the search box below the table, then the filters will also appear below the table.
How to rename the filters
Using the table builder
To edit a filter name in the table builder, click the pencil icon next to the filter. Change its name to whatever you like.
Using a shortcode
You can set custom filter names by adding a : (colon) after the filter name in the shortcode and then entering your custom wording.
In this example we have 2 filters -
tax:sector. We set a custom heading for both filters - "Region" for the
categories filter and "Location" for the custom taxonomy:
The heading for each search filter is set using the following logic:
- If you have added a name for the filter using the method described above, this takes priority.
- If you don’t set a custom heading, but the filter also appears as a column in the table, then renaming the column will also rename the filter.
- If neither of the above apply, the filter heading will come from WordPress itself (e.g. the name of the custom taxonomy).
Can I add filter widgets to the posts table?
We have integrated Posts Table Pro with the FacetWP plugin to allow you to add filter widgets to the document library. Please see our separate article about how to set this up.
Can I show the filters on their own before the loading the table?
Unfortunately not. The filters can only be appear above the table. They are designed to refine the items in the table, and not to perform a filter before the table first loads.
Can I list categories and sub-categories as separate filters?
Posts Table Pro lists all categories (or taxonomies) in a single dropdown list.
The list is nested and hierarchical so that you can see which are the parent categories and which are child categories.
Can I control the order of the dropdown items?
The filter dropdown lists are ordered alphabetically and there are no option to change them. If you have a developer, you can use the
posts_table_search_filter_get_terms_args hook to override the order options passed to the
get_terms function used to retrieve the list of filter items.
If you're using the filters to list something where alphabetical sorting isn't appropriate (e.g. dates), then you could add numbers before each item to control the order. For example, if you're using categories to filter by month, then you could name your categories '01 - January', '02 - February', and so on.
Can I filter by custom fields?
Posts Table Pro doesn't currently provide a search filter for custom fields. If you need a filter for this data, we recommend you store this as a custom taxonomy instead, as this can be filtered.
If you don't know how to create custom taxonomies then we recommend the Custom Post Type UI, Pods or Toolset plugin. These let you create custom taxonomies for any post type. You can then list the custom taxonomies and their terms as filters above the table.
Can I add checkbox filters?
There's no feature to add checkboxes to the filters. The dropdown filters are very flexible and you can add as many as you like, instead of using checkboxes.
Alternatively, you can add checkbox filters by using Posts Table Pro with FacetWP.
The categories filter isn't showing
If the categories filter isn't showing, it may be that you are displaying a custom post type in your table.
The categories filter only appears when you are showing regular WordPress posts and does not work for custom post type categories (e.g. event categories or document categories) because these are custom taxonomies.
If you are categorizing your custom post type, then you need to create a taxonomy filter instead of a categories filter.
My filters are showing options that don’t relate to the contents of the table
If you are using lazy_load, the search filters will show all possible options even if these don’t relate to items in the current table.
For example, if you are listing posts in a specific category only then the Categories filter will list all the categories on your entire website - not just the ones relating to the current table. This is because when you are using lazy load, Posts Table Pro hasn’t loaded the full content of the table and therefore doesn’t know which filter options apply to the current posts.
If this is a problem for you, here are our suggested workarounds:
- Depending on the number of posts in your table, you can disable the lazy load option. If you are not using lazy load then the filter dropdowns will only show options relating to the items in the current table.
- If you can’t disable lazy load you could create a custom taxonomy and use this as a filter instead. For example, if you are listing downloadable documents in a table and want to add a filter for the 'Staff Policies' categories only, then you could create a ‘Staff Policies’ taxonomy and add each sub-category that you need to be able to filter by. You can then add a filter dropdown for this taxonomy, instead of using the actual categories filter.