In this example the query means: “show me everything from my_table, where my_field is greater then variable 1, but less then variable 2, and user_id is equal to currently logged in users’s ID”.

Before you try to save the table you need to see if this query actually returns anything. By default %VAR1%, %VAR2% and %VAR3% are equal to empty strings, and %CURRENT_USER_ID% is equal to yours (user that creates the table – typically the Admin user, most probably with ID=1), so if you do not redefine the defaults, this query will be parsed like this on MySQL side:

Most probably such a query would not return anything, and wpDataTables would say that there’s no data to build the table upon. So to avoid this you would need to expand the placeholder configuration block, and define the default values for the variables: e.g. set %VAR1% equal to 0, and %VAR2% equal to 100. Also you can redefine the value for %CURRENT_USER_ID%, e.g. if the table does not contain any values related to the admin’s ID, set it to “15“.

The variable values are then saved in the table settings, and will be always used as default if not overriden by shortcode parameters. Only the %CURRENT_USER_ID% is not saved and the provided value is used only at the moment of the table generation, later the actual user ID is always fetched.

And if this query returns any data it will successfully create a wpDataTable.

Later you can insert this wpDataTable’s shortcode in your posts or pages, and it will fetch the data for the current user. But also you can override the variable settings. Just provide the variable values in the shortcode like this:

[ wpdatatable id=12 var1=150 var2=350]

then the values from shortcode attributes would be applied to the variable and the query would be treated like:

So with using placeholders like this you can use a single wpDataTable to produce many different output tables on different pages.

Variable placeholders are also supported in the “Default value” input in column settings. You can define %VAR1%, %VAR2% or %VAR3% in the “Default value” input of the column, then pass a value of the variable through a shortcode parameter and it will be used as default value for advanced filter on the page, and for the editor input, if the table is editable.

If you are using String for Placeholder ‘variable’ %VAR1% should be surrounded with Single Quote (‘) in the query.

Never miss new features!

Join 2000+ newsletter subscribers

Never miss notifications about new cool features, promotions, giveaways or freebies - subscribe to our newsletter! We send about one mail per month, and do our best to keep our announcements interesting.