Display number of latest images from wordpress gallery in your homepage

Displaying images from your galleries is going to be labor intensive. “Galleries” are saved as shortcodes in the post body so you would need to:

  1. Query your database for posts containing a gallery shortcode
  2. Process the post content of the result set to extract the ids of the
    gallery images
  3. And then use those ids to retrieve the images themselves.

There are a couple of queries involved and one is a LIKE query on post content. It won’t be especially fast. On the other hand…

Getting attachments is easy (gallery images are attachments but not all attachments are gallery images):

$args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'posts_per_page' => 10, // however many you want
);
$atts = new WP_Query($args);

And so is getting a set of thumbnails (featured images):

$thumbs = new WP_Query(
  array(
    'posts_per_page' => 10, // however many you want
    'meta_query' => array(
      array(
        'key' => '_thumbnail_id',
        'compare' => 'EXISTS'
      )
    ),
  )
);

I would recommend one of those two options.