Our next functionality will involve displaying a list of all posts that match a given keyword, which will involve searching our database.
Modify our
draw_panel()
function to show an input field:// draw the panel function draw_panel() { echo ' <p>Enter keywords you would like to search for and press the Search button.</p> <input type="text" id="insights-search" name="insights- search" size="25" autocomplete="off" /> <input id="insights-submit" class="button" type="button" value="Search" />'; }
This gives us an input box and a Search button to work with.
We will also add a div to display the search results in:
<input id="insights-submit" class="button" type="button" value="Search" />'; echo '<div id="insights-results"></div>'; }
Let's add input handling functionality and Ajax. Create a file,
insights.js
.First, let's add a function to submit the query using Ajax.
// Insights for WordPress...