Check if post has gallery images/media

Is there a WordPress conditional that I can use to check for gallery images/media in a post?

I do not want to check if the shortcode exist in a post.

Read More

Attached is a screenshot of what I want to check for and if is images I want to output them to the page.

Gallery has 4 image

Related posts

Leave a Reply

1 comment

  1. No Need for SQL queries in the template.

    function wpse_72594_get_attachments( $id, $mime = '' )
    {
        $args = array(
            'post_type' => 'attachment',
            'post_mime_type' => $mime,
            'post_parent' => $id
        ); 
        $attachments = get_posts($args);
        if ($attachments) 
            return $attachments;
    
        return false;
    }
    

    Then call the function like this (300 is the post ID):

    • wpse_72594_get_attachments(300), grabs all attachments
    • wpse_72594_get_attachments(300, 'image' ), only images
    • wpse_72594_get_attachments(300, 'application/pdf' ), only pdf files