I want to delete a taxonomy (both form wordpress and database) created long time ago and now no more used. How to do it? I found this function but I think it will delete all my taxonomies... and I don't know how to choos only 1 taxonomy. Could you please help me? Thanks

$results= $wpdb->get_results("select * from {$wpdb->prefix}term_taxonomy where `taxonomy` LIKE  'post_tag'",ARRAY_A );
foreach ($results as $row){     
    $wpdb->query("delete from {$wpdb->prefix}terms where `term_id` =  '".$row['term_id']."'") ;
    $wpdb->query("delete from {$wpdb->prefix}term_relationships where `term_taxonomy_id` =  '".$row['term_taxonomy_id']."'");    
$wpdb->query("delete from {$wpdb->prefix}term_taxonomy where `taxonomy` LIKE  'post_tag'");

$wpdb->query("delete from {$wpdb->prefix}icl_translations where `element_type` LIKE  'tax_post_tag'");    

You can use the function wp_delete_term

$todelete = array('one','two','three');

foreach ( $todelete as $slug ) {
  $term = get_term_by('slug', $slug, 'post_tag');
  if ( ! is_wp_error($term) && ! empty($term) )
      wp_delete_term( $term->term_id, 'post_tag');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.