Skip to content

Instantly share code, notes, and snippets.

@kjtolsma
Created November 27, 2017 10:56
Show Gist options
  • Save kjtolsma/799972f688febaa45a560a49d937b4e1 to your computer and use it in GitHub Desktop.
Save kjtolsma/799972f688febaa45a560a49d937b4e1 to your computer and use it in GitHub Desktop.
/**
* Select2
*/
$( '.pt-search' ).select2( {
minimumInputLength: 2,
placeholder: 'Search…',
ajax: {
url: 'http://somewebsite.com/wp-json/wp/v2/posts',
dataType: 'json',
data: function( params ) {
var query = {
search: params.term,
}
return query;
},
processResults: function( data ) {
return {
results: $.map( data, function( item ) {
return {
text: item.title.rendered,
id: item.id
}
} )
};
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment