4

Does anyone know how I can set an image as featured image for multiple posts.

I have posts in a seri that I would like to use the same image as featured image.

bulk edit doesn't have featured image in there though.

2
  • 2
    An image uploaded to WP Media Library stays available for multiple posts. Even though you Featured the image once for a post, you can use the same image as a featured image for almost unlimited posts. Edit each one and then add feature image - browse the media library and make the image as featured image. What's stopping you? Commented Sep 26, 2013 at 18:51
  • 1
    @MayeenulIslam what I mean to ask was how to bulk edit those posts and set featured image for all at once. Commented Sep 27, 2013 at 2:07

3 Answers 3

1

You could hook into the publish_post action, check if a featured image has been set, and if not, assign the image you want as the featured image.

The publish_post Codex page has a nice example about changing a post after it has been published.

1

we can use echo get_the_post_thumbnail($page_ID, 'thumbnail'); in php tag, where is the page/post id the page/post from where we want to display the featured image. Here is a link for it get_the_post_thumbnail

1

You can do it in your function.php

update_post_meta($post_id, '_thumbnail_id', $thumbnail_id);

You can also create a function to do this, with as custom fields of the "main" post.

function setSameThumbnails($post_id) {
    // I assume that your custom field will be something like "31,64,43" for posts ids
    $posts = get_post_meta($post_id, 'same_thumbnail', true);
    if($posts)
    {
        $posts = explode($posts, ',');
        if(is_array($posts))
        {
            foreach($posts as $post)
            {
                update_post_meta($post, '_thumbnail_id', get_post_thumbnail_id($post_id));
            }           
        }
    }
}
add_action('save_post', 'setSameThumbnails');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.