RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Return all Images (Except the Featured Image) Attached to a WordPress Post or Page

This function supports a number of our image gallery functions. The first is published on this page. There's also an article on our blog, "Find all Images (Except the Featured Image) Attached to a WordPress Post or Page", that discuses the WordPress functions in a little more depth.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Return all Images (Except the Featured Image) Attached to a WordPress Post or Page
4
 http://www.beliefmedia.com/wordpress-post-images
5
*/
6
 
7
8
 
9
  $attachments = get_posts( array(
10
    'post_type' => 'attachment',
11
    'posts_per_page' => -1,
12
    'post_status' => 'any',
13
    'post_parent' => $id,
14
    'exclude' => get_post_thumbnail_id())
15
  );
16
 
17
  /* Return array of all images */
18
  if ($attachments) {
19
    $i = 0; foreach ($attachments as $attachment) {
20
      $imagesrc = wp_get_attachment_image_src($attachment->ID, $size = 'medium');
21
      $imagesrc_medium_large = wp_get_attachment_image_src($attachment->ID, $size = 'medium_large');
22
      $imagesrc_full = wp_get_attachment_image_src($attachment->ID, $size = 'full');
23
      $imagesrc_thumbnail = wp_get_attachment_image_src($attachment->ID, $size = 'thumbnail');
24
 
25
      $images["$i"]['src'] = $imagesrc['0'];
26
      $images["$i"]['medium_large'] = $imagesrc_medium_large['0'];
27
      $images["$i"]['full'] = $imagesrc_full['0'];
28
      $images["$i"]['thumbnail'] = $imagesrc_thumbnail['0'];
29
      $images["$i"]['title'] = get_the_title($attachment->ID);
30
      $images["$i"]['caption'] = $attachment->post_excerpt;
31
      $i++;
32
    }
33
  }
34
 
35
 return $images;
36
}

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment