uploads – Using WP-CLI “wp media import” to sync files to the media library


I’m rebuilding an old website which is 3 years old.

The new website has a different sitemap and media files. For this, I have created a fresh WordPress install.

However, I’d like to maintain the old website’s media library.

I’ve copied the following directories FROM the old website:


TO the following directories on the new website:


So I can add these files to the media library, I would like to use the WP CLI command wp media import.

As there are thousands of files per upload directory, I need a way of selecting the path and importing all of the media files (.pdf, .docx, .jpg, .png etc) that are inside each directory.

I’ve found this example via the documentation:

wp media import ~/Pictures/**/*.jpg

It’s not entirely clear to me how I’d select a whole directory and every single file inside that directory.

Is this possible?

I’m aware there are plugins I can use for this job (like Add From Server), but many of these types of plugins are outdated or I don’t know the authors reputation. I’m always super careful when it comes to using plugins like this.

Sam 1 year 2021-12-17T15:20:41-05:00 0 Answers 0 views 0

Leave an answer