Adding a Column Search Drop Box to the WP_Table Class

The WP_Table class is intended to present a consistent “look” for sortable tables in the WP Admin backend. It contains most everything needed to present, paginate, process, sort and search a given table.

However, the search functionality is somewhat limited in that it will search every column of data. What if only one column is to be searched? This expansion to the WP_Table class presents a dropdown box with all specified column header names and allows for the selection of one specific column name, which will be the only column searched and reported in return.

  1. Define the columns that are to be searched.
  2. Use the column definitions to generate a drop box within the search form and display it as part of the table header.
  3. Retrieve the URL parameter selected from the drop box and use it as part of the search routine.

All of the following functions are a part of the local class definition that extends the WP_Table class.

The examples here are from the WP Security Log plugin, which records information on login attacks and error 404 attacks. These particular examples are from the Login Attacks section and therefore record such information as the attempted user name and password, the IP address from which the attack came, the reported user platform, the user agent and the date/time stamp of the attempt.

The short URL of the present article is:

Page 1 of 4
First | Prev | 1 | 2 | 3 | 4 | Next | Last
View All