• Hi All

    I need to run a wordpress CLI command to delete the images and meta data from 3 folders in wp-uploads.

    The folders are wp-uploads/2021/05, wp-uploads/2021/06, and wp-uploads/2021/07.

    Would someone be able to send through the command that I need to run?

    Previously I was referred to the following command, but this deletes all posts

    wp post delete –force $(wp post list –post_type=’attachment’ –format=ids)

    Many Thanks in advance for your assistance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @development14,
    To delete specific images and their metadata from certain folders in the wp-uploads directory using WP-CLI, you can use a combination of WP-CLI commands with Unix commands. WP-CLI doesn’t have a built-in command specifically for deleting media files by directory or folder, so we’ll need to use a workaround.
    Here’s an example command you can use:

    cd /path/to/your/wordpress/installation/wp-content/uploads
    
    # Delete images and metadata in wp-uploads/2021/05
    wp media delete $(wp media list --field=ID --path=2021/05)
    
    # Delete images and metadata in wp-uploads/2021/06
    wp media delete $(wp media list --field=ID --path=2021/06)
    
    # Delete images and metadata in wp-uploads/2021/07
    wp media delete $(wp media list --field=ID --path=2021/07)
    

    Make sure to replace /path/to/your/wordpress/installation/ with the actual path to your WordPress installation directory.

    Thanks!

    Thread Starter development14

    (@development14)

    Thank you Harsh, that’s great, will run those shortly and keep you posted

    Thread Starter development14

    (@development14)

    Hi Harsh, I believe I have the correct path to folder, but it says that the file isn’t found?

    I have navigated to the folders /uploads/, /2021/ and /05/ but none of them have worked?

    Here is the message I have received each time?

    wp media delete $(wp media list –field=ID –path=2021/05)

    -bash: /home/inekyjxs/wp-cli/bin/wp: No such file or directory

    -bash: /home/inekyjxs/wp-cli/bin/wp: No such file or directory

    /home/serverusername/public_html/wp-content/uploads?is the path I am in

    Thread Starter development14

    (@development14)

    @harshgajipara In case you get a chance to reply, thanks again for your initial post

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WordPress CLI Command Assistance’ is closed to new replies.