Home Forums General Issues Featured image, external URL


Featured image, external URL

  • Hi, i been trying make a theme change for my WordPress site.
    So i have about 900 posts with :

    Name: large-image Value: External url

    I tried using the function explained on this site:

    function get_image_id($image_url) {
    global $wpdb;
    $attachment = $wpdb->get_col($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE guid=’%s’;”, $image_url ));
    return $attachment[0];

    //Set the featured image on save of the post
    add_action(‘save_post’, ‘set_featured_image_from_image’);

    //set featured image as main image.
    function set_featured_image_from_image()
    $has_thumbnail = get_the_post_thumbnail($post->ID);

    //If there is not featured image get the other image.
    if (!$has_thumbnail) {
    //get the url of the ACF image and get the ID of that image
    $image_url = get_field(‘large_image’);
    $image_id = get_image_id($image_url);

    if ($image_id) {
    set_post_thumbnail($post->ID, $image_id);


    and _thumbnail_id.
    But it’s not working for me, all the images are hosted elsewhere my media library is empty.

    not sure what im doing wrong.
    thanks in advance

  • You can only set a featured image in WP from an image in the media library. There is an extensive answer on how to work around this posted here

    There are also plugins that will do this, also mentioned in the post

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Featured image, external URL’ is closed to new replies.