Skip to content

Instantly share code, notes, and snippets.

@stefanledin
Created November 5, 2017 21:09
Show Gist options
  • Select an option

  • Save stefanledin/66fd83eb82deec0c684ebbfb4488474a to your computer and use it in GitHub Desktop.

Select an option

Save stefanledin/66fd83eb82deec0c684ebbfb4488474a to your computer and use it in GitHub Desktop.
<footer>
<form action="/" method="GET">
<input type="search" name="search">
<input type="submit" value="Search">
</form>
<div class="search-results">
<?php
if ( isset ( $_GET['search'] ) ) {
$search_results = get_posts( ['s' => $_GET['search'] ] );
foreach ( $search_results as $post ) {
// Display the search results...
}
}
?>
</div>
</footer>
<script>
(function() {
$('form').on('submit', function() {
$.ajax({
url: '/',
method: 'GET',
success: function(response) {
var html = $(response).find('.search-results');
// Insert the search results...
}
})
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment