As we saw in Chapter 3, User Settings and Administration Pages, shortcodes are text elements that can be inserted in any page and post, that will be replaced with the content generated by the plugin when they are found. The registered callback function must prepare the output and send it back as a return value at the end of its execution.
The first part of the ch4_br_book_review_list function takes care of preparing a query array to be passed to a new instance of the WP_Query class. This class allows developers to easily extract information from the site database's post table. In this example, the parameters that are being set in the query are the internal post type name (post_type), the status of the items that we want to display (post_status), and the number of items that should be retrieved at a time (posts_per_page).
Once the query string is in place, we create a global variable called book_review_query and assign to it a new instance of a WP_Query object. Once created, we initialize it using the query string that was just assembled. If posts are found by the object, we output HTML code to create a table and use a while loop to cycle through all the items found and display their title and author using a code similar to the previous two recipes.
As part of this recipe, we have seen that if more entries exist for the custom post type than the value specified with the posts_per_page query argument, navigation controls are added under the table of entries but will not work correctly, since we manually created the query string. To rectify the situation, we use the get_query_var function to see if a page number was requested. If that is the case, and the page number is not 1, we add that number to our query parameters.