1

Is there a way I can exclude the post thumbnail AND a custom field with the value "_lm_comm_logo" from this query that pulls all of the images associated with a particular post?

<?php $args = array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID); ?>
                <?php if ( $photos = get_posts($args) ) : ?>
                    <div class="slides">
                        <?php foreach ( $photos as $photo ) : ?>
                            <div class="slide">
                                <a href="<?php echo $photo->guid; ?>" class="lightbox" rel="community[<?php echo $post->ID; ?>]"><?php echo wp_get_attachment_image($photo->ID, 'thumbnail'); ?></a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
  • are you storing the custom field as an actual attachment or just the URL as a text field? – Norcross Jan 3 '12 at 5:36
  • 3
    Rather than editing your question to post the solution, please post your entire solution as an answer and mark it as "the" answer so that others can find it. – EAMann Jan 3 '12 at 16:32
1

The asker refused to post his solution as answer, so I took the liberty to get this question out of our growing Unanswered Questions list …

<?php 
$logo = get_post_meta($post->ID, '_lm_comm_logo', true);
$map  = get_post_meta($post->ID, '_lm_comm_map', true);

$args = array(
    'numberposts'    => -1, 
    'orderby'        => 'menu_order', 
    'order'          => 'ASC', 
    'post_type'      => 'attachment', 
    'post_mime_type' => 'image', 
    'exclude'        =>  array($logo,$map),
    'post_parent'    => $post->ID
); 

if ( $photos = get_posts($args) ) : ?>
    <div class="slides">
        <?php foreach ( $photos as $photo ) : ?>
            <div class="slide">
                <a href="<?php 
                    echo $photo->guid; 
                ?>" class="lightbox" rel="community[<?php 
                    echo $post->ID; 
                ?>]"><?php 
                    echo wp_get_attachment_image($photo->ID, 'thumbnail'); 
                ?></a>
            </div>
        <?php endforeach; ?>
    </div>
<?php
endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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