Bulk import external images and set them as posts featured images

Featured Theme Forums CSS and PHP Bulk import external images and set them as posts featured images

This topic contains 0 replies, has 1 voice, and was last updated by  Mariano Alesandro 2 years, 5 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #13398

    Mariano Alesandro
    Participant

    Hi Zeaks!
    I’m re-posting a post I did at wordpress and stackoverflow, but got no answer.
    Since you have already helped me once and you seem to really know your way around WP, I thought you might be able to help again.
    Here it goes:

    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.
    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.
    My question is, 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);
    }

    If you can help me out with any idea, I’d really appreciate it.
    I have read [URL=’http://www.xpertdeveloper.com/2012/03/featured-image-in-wordpress-by-code/’]this article[/URL] and it looks like a starting point, but I don’t really know if this way also adds the different image sizes, etc.
    Best regards,
    Mariano

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

    If you can help me out with any idea, I’d really appreciate it.
    I have read this article and it looks like a starting point, but I don’t really know if this way also adds the different image sizes, etc.
    Best regards,
    Mariano

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.