Created
November 27, 2017 10:56
-
-
Save kjtolsma/799972f688febaa45a560a49d937b4e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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