我有一个问题,不能得到那个重奏。我所做的是以编程方式将子类别创建为父类别,并通过处理csv-文件,以编程方式为子类别创建帖子:
h 19-Sub 2H 210H 111--Sub 2-2H 212H 113-Sub 3H 214f 215
这个很好用。
我现在要做的是:在再次运行脚本之前删除这些子类别中的所有子类别和所有帖子。只有父类应该保留,其他的东西都应该消失。
在使用$wpdb、直接sql语句或任何wordpress-函数的单个查询中,这是可能的吗?
谢谢你,并向你问好,汤姆
发布于 2019-10-27 15:14:36
听起来很蠢..。但通过问这个问题,我找到了一个解决办法:
function delete_posts_title($partner) {
//delete all posts
$catposts = get_posts( array(
'category' => $partner['kategorie_id'],
'numberposts' => -1
) );
$i = 0;
foreach($catposts as $post) {
//exclude posts that are in these categories, too
if(!in_category( array(1,4145),$post->ID)) {
//echo "<pre>".$post->post_title." ". $i ."</pre>";
wp_delete_post( $post->ID, false );
++$i;
}
}
//delete all subcategories
$args = array('child_of' => $partner['kategorie_id']);
$categories = get_categories( $args );
foreach($categories as $category) {
wp_delete_category( $category->term_id );
}}
https://stackoverflow.com/questions/58579390
复制相似问题