WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to select some attachements based on an attachement caption. I need to do this for a seperate download page. On the download page i want to display all attachment which caption equals "downloads". So this way i can be selective of post attachments which can and can't be downloaded

At the moment i have this code to select all the attached pdf's as downloable files, but i like to select some attached images and deselect some pdf's.

    $args = array('post_parent' => $atts['product_id'],
    'post_status' => 'inherit', 'post_type' => 'attachment',
    'post_mime_type' => 'application/pdf', 'order' => $order, 'orderby' => $orderby);
$attachments = get_posts($args);
        $i = 1;
        foreach ($attachments as $attachment) {

i am also able to select images based on there given thumbnail name with


but how to select based on caption??


share|improve this question
up vote 0 down vote accepted

Ok found a solution by using this in the loop

if ($attachment->post_excerpt == 'download') {

Where i have put "download" in the caption textfield.

hmmm, what if i want to select an image with 2 or more different captions?

share|improve this answer

Your Answer


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.