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??



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?

| improve this answer | |

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.