更改 wpDataTables 中的 iDisplayLength

Change iDisplayLength in wpDataTables

my site I am using the plugin wpDataTables 上(基于 jQuery DataTables)。例如,当我在搜索字段中键入 HB 时,会得到 10 个结果(价格),但我只需要 6.

所以我想将 iDisplayLength 从 10 更改为 6 但它没有按照建议工作@ datatables.net

这里有一些 Front-end callbacks via JS。是否可以通过这些前端回调实现?

观看 Using filters and actions 上的视频,其中 wpdatatables 的作者几乎完全按照您的意愿解释了如何做。

基本上,您需要将以下代码添加到 WordPress 主题的 functions.php 中。

请注意,此代码将影响您网站上的所有 table。如果您想定位特定的 table,那么您需要仅在 $table_id 等于您的 table ID 时更改 iDisplayLength 参数。

function mytheme_wpdatatables_filter_table_description($object, $table_id){
   $object->dataTableParams->iDisplayLength = 6;

   return $object;
}
add_filter('wpdatatables_filter_table_description', 'mytheme_wpdatatables_filter_table_description', 10, 2);