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

Question

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:

/old-website/wp-content/uploads/2018/
/old-website/wp-content/uploads/2019/
/old-website/wp-content/uploads/2020/
/old-website/wp-content/uploads/2021/

TO the following directories on the new website:

/new-website/wp-content/uploads/migration/uploads/2018/
/new-website/wp-content/uploads/migration/uploads/2019/
/new-website/wp-content/uploads/migration/uploads/2020/
/new-website/wp-content/uploads/migration/uploads/2021/

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.

0
Sam 8 months 2021-12-17T15:20:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse