Bulk delete unattached images using WP CLI & exclude specific authors
-
I’m trying to delete all images within a month’s archive that are not assigned to a post and have not been uploaded by the admin (user_id 1). The number of affected images is large (>50.000 images), so they have to be deleted image by image.
The following command works great but how can I exclude images uploaded by admin?
for id in $(wp db query "SELECT ID FROM wp_posts WHERE post_date>='2020-11-01' AND post_date<='2020-11-30' AND post_type='attachment' AND post_parent=0" --silent --skip-column-names) do wp post delete --force $id done
I tried a lot of things like
for id in $(wp db query "SELECT ID FROM wp_posts WHERE post_date>='2020-11-01' AND post_date<='2020-11-30' AND post_type='attachment' AND post_parent=0 AND post_author='-1'" --silent --skip-column-names) do wp post delete --force $id done
But nothing works. Any help would be appreciated.
Thank you!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Bulk delete unattached images using WP CLI & exclude specific authors’ is closed to new replies.