This recipe starts by registering an action callback that will be executed when WordPress renders the various filter controls that are available for each post type listing. When the function is called, it retrieves a global variable to know the post type that is currently being displayed and determine if it should show the book type filter list. It also accesses the global post query variable to see if a book type filter is already in place and sets the correct drop-down list entry to be selected, if there is one.
The callback then proceeds to use the wp_dropdown_categories function to display a list of all of the taxonomy items registered for book types. This utility function expects to receive an array of parameters that determine which taxonomy list to display, the name of the drop-down list field name, and the label to be displayed for the option to show all the types. This array should also contain a few parameters to determine the order in which the items should be displayed, specify the item to set as selected, indicate the maximum depth to show for hierarchical taxonomies, and determine whether or not items count and empty items be shown.
Once the new book type selection list is in place, selecting an entry and clicking on the Filter button triggers a refresh of the web page and leads to the second registered callback that was put in place after being executed. The filter function receives the current WordPress post query object and starts by first getting a pointer to the query variables that are stored inside of the query object. With this in hand, it moves on to verify that a book type is part of the query variables and that it is numeric. If the result is positive, it replaces the numeric value with the textual name for the selected book type so that the query can take place.
Once all of this code is executed, users are able to quickly filter which book types should be displayed in the Book Reviews management page. They are also still able to use the column sorting mechanism implemented in the previous recipe.