This recipe implements a simple search engine by displaying a short form and capturing a user search string using the standard HTML GET method. If a search string is found in the page address, we will modify the bug retrieval query that was in place by adding a where clause that looks for the search string anywhere in the bug_title or bug_description fields.
While it might seem natural to insert the search string directly in the query and execute it, we use the wpdb class' prepare method to assemble the query and validate the search string to avoid malicious intent. This method works in a very similar way to the standard PHP sprintf function, with placeholders to represent the places where variables should be substituted.
The remainder of the shortcode display function remains identical, displaying a list of varying length depending on the presence of a search string and the number of entries that match the query.