DEV Community

Diego Carrasco Gubernatis
Diego Carrasco Gubernatis

Posted on • Originally published at diegocarrasco.com on

1 1

How to import several folders with files into WordPress Media Library using wp-cli

Code in terminal
I was in a pinch. I needed to import 12.000+ files with different filetypes into a Wordpress Media Library. The easy part, uploading the files with the folder structure to wp-content/uploads was done quickly, but Wordpress Media Library didn’t “see” the files.

After some quick reading I found out that they need to be imported into the Library, and after some more reading I found wp-cli works with ‘xargs’ in Bash.

Helpful links at Dev Notes and StackOverflow

The command I ended using is as follows through SSH:

find /tmp -name '*.pdf' -or -name '*.doc' -or -name '*.jpg' -or -name '*.xls' -or -name '*.docx' -or -name '*.xlsx' | xarg wp media import
Enter fullscreen mode Exit fullscreen mode

Then you can regenerate all the thumbnails using

wp media regenerate --all
Enter fullscreen mode Exit fullscreen mode

I recommend using screen as the import could stop if the connection gets down, because for me on a Digital Ocean server with 2gb took around 2-3 hours.

Source

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more