Last active
February 27, 2019 15:01
-
-
Save csalzano/7a9f09b0da015308963f4049707b7eb8 to your computer and use it in GitHub Desktop.
JavaScript that deletes a term from a WordPress custom taxonomy
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
//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