Filtering posts tables by keyword or search term
Search box above the table
By default, Posts Table Pro displays tables with a search box above the table (top-right). This allows people to instantly filter the table to products with a specific keyword or search term.
In this example, the user has typed the term “policy” into the search box. This has filtered the table to the 2 items which match that term:
If you are not using lazy load then the search box will search all data in the table, so users can search by category, tag, date, etc. The search box is more restricted if your table uses lazy load.
Posts Table Pro also has options to change the position of the search box or hide it altogether.
Search term option
You can also choose to filter the contents of the table when it is first displayed. To do this, add the
search_term option to your shortcode. E.g.
- When using lazy load, the
search_termoption will only search the post title and content – the other columns will not be searched.
- The search is case insensitive.
- As with the main WordPress search, the search is done by keyword, not individual words. So if you use
search_term="policy1", then it will match products with the name “policy1”, “policy12”, “Policy1 – HR”, etc.
Can I link to a pre-filtered or pre-searched table?
The search box that appears above the table does not create a URL for each search term because it uses AJAX and displays results on the same page. If you wish to link to a pre-searched table then there are 2 ways to do this:
- Use the
search_termshortcode option (described above) to create a table that is pre-filtered for a specific search term, or;
- Use these instructions to add the Posts Table Pro layout to the search results template in your theme. The WordPress search results page has a unique URL for each search term which you can link to, so you can link directly to this. This is the format for linking to a specific search term (in this case, we are doing a search for ‘staff policies’: https://yourwebsite.com/?s=staff+policies
Can I load a pre-filtered table and then allow users to expand the selection to view all posts?
Some people like to use the
search_term option to create a pre-filtered table, while giving their users the option to remove the search term and view a wider selection of posts that don’t match this keyword.
This is possible if you are using the lazy load option in Posts Table Pro. Use the search term option to filter the table by a specific keyword, as described above. Your users can then delete the keyword from the search box. The table will re-load with all possible posts, including those that don’t match that keyword.
Please note that this will not work if lazy load is disabled.