我想删除一个很久以前创建的分类法(wordpress和数据库),现在不再使用了。怎么做?我找到了这个函数,但我想它会删除我所有的分类法。。。而且我不知道如何只选择一种分类法。你能帮帮我吗?谢谢
<?php
require_once($_SERVER[\'DOCUMENT_ROOT\']."/wp-load.php");
$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\'");
?>
最合适的回答,由SO网友:gmazzap 整理而成
您可以使用该功能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\');
}