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.

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; ?>
share|improve this question
    
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
add comment

1 Answer

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;
share|improve this answer
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.