Skip to content

Instantly share code, notes, and snippets.

@nayemDevs
Forked from alamgircsebd/delete.php
Created January 4, 2023 04:29
Show Gist options
  • Save nayemDevs/d1140eda57e666d4f0b9335c63042b4f to your computer and use it in GitHub Desktop.
Save nayemDevs/d1140eda57e666d4f0b9335c63042b4f to your computer and use it in GitHub Desktop.
Scripts for Delete WooCommerce Products by User ID
<?php
$userID = 2;
$args = array( 'author' => $userID, 'post_type' => 'product', 'posts_per_page' => -1, 'post_status' => array( 'publish', 'pending', 'draft', 'future' ) );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
wp_delete_post( get_the_ID(), true );
echo '<ul>';
echo '<li>Deleted product ID: ' . get_the_ID() . '</li>';
echo '</ul>';
}
/* Restore original Post Data */
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment