/** * Delete posts by custom post type. * * @static * @since 5.0 * @param array $delete_options Options for deleting posts * @return int $posts_deleted Number of posts that were deleted */ public static function delete_posts_by_post_type($delete_options) { // Backward compatibility code. Will be removed in Bulk Delete v6.0 if (array_key_exists('types_op', $delete_options)) { $delete_options['date_op'] = $delete_options['types_op']; $delete_options['days'] = $delete_options['types_days']; } $delete_options = apply_filters('bd_delete_options', $delete_options); $count = 0; $selected_types = $delete_options['selected_types']; foreach ($selected_types as $selected_type) { $type_status = BD_Util::split_post_type_status($selected_type); $type = $type_status['type']; $status = $type_status['status']; $options = array('post_status' => $status, 'post_type' => $type); $options = bd_build_query_options($delete_options, $options); $post_ids = bd_query($options); foreach ($post_ids as $post_id) { // $force delete parameter to custom post types doesn't work if ($delete_options['force_delete']) { wp_delete_post($post_id, true); } else { wp_trash_post($post_id); } } $count += count($post_ids); } return $count; }