Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i am trying to exclude multiple post thumbnails from attachments.

i have the following thumbnails setup in my functions.php:

$thumb = new MultiPostThumbnails(array(
    'label' => 'Client Logo',
    'id' => 'client-logo',
    'post_type' => 'clients'
    )
);

$thumb = new MultiPostThumbnails(array(
    'label' => 'Portfolio Home Image',
    'id' => 'port-home-image',
    'post_type' => 'clients'
    )
);

$thumb = new MultiPostThumbnails(array(
    'label' => 'Home Slide Image',
    'id' => 'home-slide-image',
    'post_type' => 'clients'
    )
);

i then have the following code, within the loop to pull in all image attachements and disaply them

<?php
      $thumb_id = get_post_thumbnail_id( $post_id );
      $args = array(
      'post_type' => 'attachment',
      'numberposts' => $nimg,
      'post_mime_type' => 'image',
      'post_status' => null,
      'post_parent' => $post->ID,
      'exclude' => $thumb_id
      );
      $attachments = get_posts($args);
      if ($attachments) {
      foreach ($attachments as $attachment) {
      //echo apply_filters('the_title', $attachment->post_title);
      echo wp_get_attachment_image( $attachment->ID, array (650,650));

     }
      }

?>

this line: $thumb_id = get_post_thumbnail_id( $post_id ); excludes the featured post thumbnail.

any ideas on how i can exclude my 3 other thumbnails?

any help would be greatly appreciated.

Thanks Danyo

http://wordpress.org/extend/plugins/multiple-post-thumbnails

share|improve this question
add comment

2 Answers

     $thumb_id = get_post_thumbnail_id(get_the_ID());
     $bg_id = MultiPostThumbnails::get_post_thumbnail_id('work', 'background-image', $post->ID);
     $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID,
       'exclude' => array($thumb_id, $bg_id)

      );
share|improve this answer
add comment

I've only modified the 'exclude' line. It's not tested but it should work.

<?php
      $thumb_id = get_post_thumbnail_id( $post_id );
      $args = array(
      'post_type' => 'attachment',
      'numberposts' => $nimg,
      'post_mime_type' => 'image',
      'post_status' => null,
      'post_parent' => $post->ID,
      'exclude' => $thumb_id, MultiPostThumbnails::get_post_thumbnail_id('clients', 'client-logo', $post_id), MultiPostThumbnails::get_post_thumbnail_id('clients', 'port-home-image', $post_id), MultiPostThumbnails::get_post_thumbnail_id('clients', 'home-slide-image', $post_id)
      );
      $attachments = get_posts($args);
      if ($attachments) {
      foreach ($attachments as $attachment) {
      //echo apply_filters('the_title', $attachment->post_title);
      echo wp_get_attachment_image( $attachment->ID, array (650,650));

     }
      }

?>
share|improve this answer
    
thanks for the response, unfortunately is doesnt seem to work? still including those images –  Danyo Sep 9 '11 at 9:18
    
Can you tell me what this line returns? MultiPostThumbnails::get_post_thumbnail_id('clients', 'client-logo', $post_id) –  koskoz Sep 9 '11 at 11:31
    
Thanks, but this line still doesnt remove the desired image.. –  user8857 Sep 22 '11 at 9:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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