$post_type, // 'any' skips trashed posts, so list every status explicitly. 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'trash', 'auto-draft', 'inherit' ), 'fields' => 'ids', 'posts_per_page' => 100, 'no_found_rows' => true, ) ); foreach ( $ids as $id ) { wp_delete_post( $id, true ); } } while ( ! empty( $ids ) ); } // Taxonomies are not registered during uninstall, so register them and remove the terms through the API. if ( ! taxonomy_exists( 'spfaq_category' ) ) { require_once plugin_dir_path( __FILE__ ) . 'includes/core/class-spfaq-content.php'; SPFAQ_Content::register_faq(); } foreach ( array( 'spfaq_category', 'spfaq_tag', 'spfaq_group' ) as $taxonomy ) { $previous = array(); do { $term_ids = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'fields' => 'ids', 'number' => 100, ) ); if ( is_wp_error( $term_ids ) || empty( $term_ids ) || $term_ids === $previous ) { break; // Done, or nothing more could be deleted. } foreach ( $term_ids as $term_id ) { wp_delete_term( $term_id, $taxonomy ); } $previous = $term_ids; } while ( true ); } // FAQ assignments stored on other post types, for example WooCommerce products. $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE meta_key LIKE %s OR meta_key LIKE %s', $wpdb->postmeta, $wpdb->esc_like( '_spfaq_' ) . '%', $wpdb->esc_like( 'spfaq_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery // Custom tables. foreach ( array( 'spfaq_events', 'spfaq_search_events', 'spfaq_search_clicks' ) as $suffix ) { $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . $suffix ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery } // Options and transients. $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', $wpdb->options, $wpdb->esc_like( 'spfaq_' ) . '%', $wpdb->esc_like( '_transient_spfaq_' ) . '%', $wpdb->esc_like( '_transient_timeout_spfaq_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery wp_cache_flush(); } if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0, ) ) as $spfaq_blog_id ) { switch_to_blog( $spfaq_blog_id ); spfaq_uninstall_site(); restore_current_blog(); } } else { spfaq_uninstall_site(); }