您可以使用taxquery
, 并循环遍历结果,逐个删除它们。
wp_delete_post()
您可以选择将帖子移动到垃圾箱,或强制删除它,所以请小心。
为了确保删除正确的帖子,您可以创建要删除的帖子列表,而不是直接删除它们。
瞧,代码来了:
function f711_delete_all_posts_from_taxonomy() {
$args = array(
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'numberposts\' => -1,
\'post_type\' => \'post\', // or whatever posttype you want to delete
\'tax_query\' => array(
array(
\'taxonomy\' => \'yourtaxonomy\',
\'field\' => \'slug\',
\'terms\' => \'slug-to-be-deleted\'
)
)
);
$posts = get_posts( $args );
foreach( $posts as $thispost ) {
wp_delete_post( $thispost->ID, true ); //set second parameter to false to move the post to the trash
}
}