Bulk import external images into WordPress and set them as posts featured images

I have a Joomla blog running, with a custom way of using article images.
For each article created, its image has to be uploaded to an images folder using the title format “article_image_xxx” where xxx represents the post’s ID. Then when displaying the article, Joomla reads the image and shows it up.

I am now setting up a WordPress site, and have migrated all the Joomla posts into WordPress.
It worked like a charm using the FG Joomla to WordPress plugin, and all the posts were imported maintaining their Joomla article ID.

Read More

However, in order to set up the Featured Image, I need to do it manually post per post.
I have checked if there were plugins addressing this problem, but found nothing.
I don’t want to go over more than a thousand articles, and since the problem is pretty much specific to my case, I want to create some function that I can run.

What’s the best way to approach this using WordPress functions?

What I have in mind is something like this (pseudocode):

posts = get_all_posts;
foreach posts as post {
 post_id = post[id];
 post_featured_image = "uploads/article_image".post_id;
 wordpress_function_set_featured_image(post_id, post_featured_image);
}

Can anyone shed some light on how to proceed?

Related posts

Leave a Reply