Skip to content

Instantly share code, notes, and snippets.

@csalzano
Last active February 27, 2019 15:01
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 csalzano/7a9f09b0da015308963f4049707b7eb8 to your computer and use it in GitHub Desktop.
Save csalzano/7a9f09b0da015308963f4049707b7eb8 to your computer and use it in GitHub Desktop.
JavaScript that deletes a term from a WordPress custom taxonomy
//find & delete a term in our Transmission custom taxonomy
let terms = new wp.api.collections.Transmission();
terms.fetch().done( function( t ){
let target = t.find( x => 'automatic' === x.slug );
if( ! target ) { return; }
jQuery.ajax({
method: 'DELETE',
url: myplugin.rest_base_url + 'wp/v2/transmission/' + target.id + '?force=true',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', myplugin.nonce ); //must be wp_create_nonce( 'wp_rest' ), see paragraph 4 https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment