WordPress.org

Ready to get started?Download WordPress

Forums

Can one set post thumbnail from a function? (5 posts)

  1. Taylor Baybutt
    Member
    Posted 2 years ago #

    My client would like to set the post thumbnail from an image url on another website. I understand why this is not built in with the image needing to be uploaded to be resized. However, is there any way to upload the image from a function. If so, I could fulfill their request using custom fields.

    I would need a function something like

    set_post_tumbnail($post_id, $image_url)

    I can't seem to find that this exists. Has anyone jumped this hurdle?

  2. sm_rasmy
    Member
    Posted 2 years ago #

    first thing first
    ididt catch you exactly wat you want
    so
    here the way to make a post thumbanil
    http://www.doitwithwp.com/show-featured-image-wordpress-posts/

    then
    here the way to get the thumbanil url

    add this code in the loop

    <?php
    $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id);
    $image_url = $image_url[0];
    ?>
  3. Taylor Baybutt
    Member
    Posted 2 years ago #

    That's all well and good but what I want to do is assign an image url (say from an external website) to a post_id as the post thumbnail.

    This would require downloading the image and maybe that is different than uploading an image to the system.

    So the function would probably be something like

    set_post_thubnail($post_id,$image_url,$directory)

    I don't think something like that exists but I can't confirm or deny.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

  5. Taylor Baybutt
    Member
    Posted 2 years ago #

    That looks about right. Thanks so much! I will attempt to do it this weekend.

Topic Closed

This topic has been closed to new replies.

About this Topic