Creating a new shortcode to display custom table data is done in a very similar way as in previous recipes. First, we declare the new code, along with the name of the function that will be called to generate text to replace it when found in posts or pages. Then, we create a display function to prepare all the output and return it to WordPress.
The only distinction here is in the way we query the information. The recipe uses the get_results method of the wpdb class to query all the bugs that exist in the custom database table using the SELECT SQL command. After this call is executed, all the items found are returned in an associative array that can easily be displayed in table form using a foreach loop.
If no entries were found, the recipe displays a simple message to inform the visitor.