如何永久删除分类

时间:2013-09-23 作者:advalue

我想删除一个很久以前创建的分类法(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\'");    
?>

1 个回复
最合适的回答,由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\');
}

结束

相关推荐

按字母顺序排序:如何在MySQL查询中设置ORDER=ASC?

我有这个function: global $wpdb; // adjust the query to fit your needs $posts = $wpdb->get_results( $wpdb->prepare( \"SELECT * FROM $wpdb->posts WHERE post_type = \'post\' AND post_status = \'publish\' AND post_t