---
description: >-
  https://wordpress.stackexchange.com/questions/115792/set-featured-image-for-multiple-posts
---

# Set featured image for multiple posts (ok)

**Create multiple featured for posts**

```php
function setSameThumbnails() {
  $posts = get_posts(array(
    'fields'          => 'ids', // Only get post IDs
    'posts_per_page'  => -1
  ));
  if($posts)
  {
    foreach($posts as $post)
    {
        update_post_meta($post, '_thumbnail_id', get_post_thumbnail_id(5816593));
    }   
  }
}
add_action('save_post', 'setSameThumbnails');
```

**Create multiple featured for products**

```
function setSameThumbnails()
{
  $posts = get_posts(array(
    'post_type'        => 'product',
    'fields'          => 'ids', // Only get post IDs
    'posts_per_page'  => -1
  ));
  if ($posts) {
    foreach ($posts as $post) {
      update_post_meta($post, '_thumbnail_id', get_post_thumbnail_id(14822));
    }
  }
}
add_action('save_post', 'setSameThumbnails');
```
