diff --git a/readme.txt b/readme.txt index cdf476e..cd3f228 100644 --- a/readme.txt +++ b/readme.txt @@ -92,6 +92,7 @@ Is this plugin prepared for multisites? Yes. * Removed some unnecessary
tags. * Removed the extra Select option from the page lenght menu. * Added the default page lenghts and the option for All in the page lenght dropdown. +* Added the choosen page lenght as an option to the dropdown if it's not one of the default options. = 4.1.0 = * Compatibility with WordPress version 6.7.1 diff --git a/wp-jquery-datatable.php b/wp-jquery-datatable.php index f232252..fc87883 100644 --- a/wp-jquery-datatable.php +++ b/wp-jquery-datatable.php @@ -230,6 +230,25 @@ function wp_jdt_shortcode($atts) $table_searching = ($atts['searching'] === 'true') ? 'true' : 'false'; $table_length_menu = array(10, 25, 50, 100, -1); + if (!in_array($table_page_length, $table_length_menu)) { + // Add the missing page length option to the array + $table_length_menu[] = (int)$table_page_length; + + // Temporarily remove -1 ("All") if present to preserve its position at the end + $has_all = false; + if (($key = array_search(-1, $table_length_menu)) !== false) { + unset($table_length_menu[$key]); + $has_all = true; + } + + // Sort the remaining numeric options in ascending order + sort($table_length_menu); + + // Append -1 back to the end of the array + if ($has_all) { + $table_length_menu[] = -1; + } + } // css and js wp_enqueue_style('jdt-style-data-tables');