Skip to content

Instantly share code, notes, and snippets.

@alessandrotesoro
Forked from joehoyle/wp-api-select2.js
Created January 25, 2016 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessandrotesoro/d90d173dd754bbf7ee71 to your computer and use it in GitHub Desktop.
Save alessandrotesoro/d90d173dd754bbf7ee71 to your computer and use it in GitHub Desktop.
this.$el.find( '.taxonomy-terms' ).select2({
multiple: true,
ajax: {
url: WP_API_Settings.root + 'wp/v2/terms/' + this.options.taxonomy.slug,
data: function( term, page ) {
return {
search: term,
page: page,
_envelope: true
}
},
results: function( data, page ) {
return {
results: data.body.map( function( term ) {
return { text: term.name, id: term.id };
} ),
more: data.headers['X-WP-TotalPages'] > page
}
}
},
width: '100%'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment