Skip to content

Instantly share code, notes, and snippets.

@sepehr125
Last active February 3, 2017 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepehr125/239f59e885f92115c517 to your computer and use it in GitHub Desktop.
Save sepehr125/239f59e885f92115c517 to your computer and use it in GitHub Desktop.
jQuery( document ).ready( function( $ ) {
$('#s').autocomplete({
serviceUrl: '/wp-admin/admin-ajax.php?action=autocompleteCallback',
dataType: 'json',
paramName: 'term',
transformResult: function(response) {
return {
suggestions: $.map(response.results, function(dataItem) {
return { value: dataItem.title, data: dataItem.url };
})
};
},
onSelect: function(suggestion) {
window.location.replace(suggestion.data);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment