How it works...
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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access