Table of Contents
How to pre-filter a wpDataTables table through the URL
Say you have one product table on your site and want to send a customer a link that shows only the products from one supplier. You don’t need a second table: add a parameter to the page URL, and the table opens already searched or filtered. You can fill the main search box, set column filters or pass placeholder values this way.
How do I fill the search box through the URL?
Add wdt_search with the search value to the page URL:
https://example.com/products/?wdt_search=lamp
The table opens as if the visitor had typed “lamp” in the search box above it, and the info line below the table shows how many rows match, for example “filtered from 10 total entries”.
How do I set column filters through the URL?
Column filter values use the parameter wdt_column_filter[KEY] with the filter value. KEY is either the position of the column, counted from 0 for the first column, or the original header of the column from the source, such as the CSV header or the MySQL column name:
https://example.com/products/?wdt_column_filter[1]=Linz
https://example.com/products/?wdt_column_filter[supplier]=Linz
For range filters, separate the from and to values with a pipe:
https://example.com/products/?wdt_column_filter[3]=60|80
The column needs a filter. Read How to add column filters to set one up. Open the link once and check that the table opens filtered before you share it.
How do I pass placeholder values through the URL?
Add wdt_var1 to wdt_var9 to set the variable placeholders %VAR1% to %VAR9%. Use this when a placeholder is a default filter value or part of the query of a MySQL table:
https://example.com/products/?wdt_var1=lamps
https://example.com/products/?wdt_var1=lamps&wdt_var2=2026
Separate several parameters with &. Read Table placeholders to see where placeholders work.
What should I remember about pre-filtering through the URL?
Add ?wdt_search=value to fill the search box. Column filters use wdt_column_filter[KEY]=value, with the position from 0 or the original header as the key and from|to for ranges, and placeholder values use wdt_var1 to wdt_var9. Join parameters with &, set up a filter for each filtered column, and check the link before you share it. Cascade filtering is not supported.
Where can I read more?
These pages cover filters and placeholders: